File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -46,11 +46,10 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns {
46
46
_: Span ,
47
47
_: HirId ,
48
48
) {
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 } ;
54
53
55
54
let FnRetTy :: Return ( return_ty_hir) = & decl. output else { return } ;
56
55
Original file line number Diff line number Diff line change 1
1
#![ warn( clippy:: unnecessary_box_returns) ]
2
2
3
+ trait Bar {
4
+ fn baz ( & self ) -> Box < usize > ;
5
+ }
6
+
3
7
struct Foo { }
4
8
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
+
5
16
// lint
6
17
fn boxed_usize ( ) -> Box < usize > {
7
18
Box :: new ( 5 )
Original file line number Diff line number Diff line change 1
1
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
3
3
|
4
4
LL | fn boxed_usize() -> Box<usize> {
5
5
| ^^^^^^^^^^ help: change the return type to: `usize`
6
6
|
7
7
= note: `-D clippy::unnecessary-box-returns` implied by `-D warnings`
8
8
9
9
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
11
11
|
12
12
LL | fn boxed_foo() -> Box<Foo> {
13
13
| ^^^^^^^^ help: change the return type to: `Foo`
You can’t perform that action at this time.
0 commit comments