Skip to content

Commit e2c22d6

Browse files
committed
Don't lint on impls for now
1 parent 14ae306 commit e2c22d6

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

clippy_lints/src/unnecessary_box_returns.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns {
4646
_: Span,
4747
_: HirId,
4848
) {
49-
// it's unclear what part of a closure you would span, so for now it's ignored
50-
// if this is changed, please also make sure not to call `hir_ty_to_ty` below
51-
if matches!(fn_kind, FnKind::Closure) {
52-
return;
53-
}
49+
// It's unclear what part of a closure you would span, so for now it's ignored.
50+
// Trait implementations should also not be linted.
51+
// If this is changed, please also make sure not to call `hir_ty_to_ty` below.
52+
let FnKind::ItemFn(..) = fn_kind else { return };
5453

5554
let FnRetTy::Return(return_ty_hir) = &decl.output else { return };
5655

tests/ui/unnecessary_box_returns.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#![warn(clippy::unnecessary_box_returns)]
22

3+
trait Bar {
4+
fn baz(&self) -> Box<usize>;
5+
}
6+
37
struct Foo {}
48

9+
impl Bar for Foo {
10+
// don't lint: this is a problem with the trait, not the implementation
11+
fn baz(&self) -> Box<usize> {
12+
Box::new(42)
13+
}
14+
}
15+
516
// lint
617
fn boxed_usize() -> Box<usize> {
718
Box::new(5)

tests/ui/unnecessary_box_returns.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: function returns `Box<usize>` when `usize` implements `Sized`
2-
--> $DIR/unnecessary_box_returns.rs:6:21
2+
--> $DIR/unnecessary_box_returns.rs:17:21
33
|
44
LL | fn boxed_usize() -> Box<usize> {
55
| ^^^^^^^^^^ help: change the return type to: `usize`
66
|
77
= note: `-D clippy::unnecessary-box-returns` implied by `-D warnings`
88

99
error: function returns `Box<Foo>` when `Foo` implements `Sized`
10-
--> $DIR/unnecessary_box_returns.rs:11:19
10+
--> $DIR/unnecessary_box_returns.rs:22:19
1111
|
1212
LL | fn boxed_foo() -> Box<Foo> {
1313
| ^^^^^^^^ help: change the return type to: `Foo`

0 commit comments

Comments
 (0)