File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change 1
1
#![ warn( clippy:: unused_box) ]
2
2
3
- fn foo ( ) -> Box < usize > {
3
+ struct Foo { }
4
+
5
+ // lint
6
+ fn boxed_usize ( ) -> Box < usize > {
4
7
Box :: new ( 5 )
5
8
}
6
9
10
+ // lint
11
+ fn boxed_string ( ) -> Box < Foo > {
12
+ Box :: new ( Foo { } )
13
+ }
14
+
15
+ // don't lint: str is unsized
16
+ fn boxed_str ( ) -> Box < str > {
17
+ "Hello, world!" . to_string ( ) . into_boxed_str ( )
18
+ }
19
+
20
+ // don't lint: this has an unspecified return type
21
+ fn default ( ) { }
22
+
23
+ // don't lint: this doesn't return a Box
24
+ fn string ( ) -> String {
25
+ String :: from ( "Hello, world" )
26
+ }
27
+
7
28
fn main ( ) {
8
- // test code goes here
29
+ // don't lint: this is a closure
30
+ let a = || -> Box < usize > { Box :: new ( 5 ) } ;
9
31
}
Original file line number Diff line number Diff line change 1
1
error: function returns `Box<usize>` when `usize` implements `Sized`
2
- --> $DIR/unused_box.rs:3:13
2
+ --> $DIR/unused_box.rs:6:21
3
3
|
4
- LL | fn foo () -> Box<usize> {
5
- | ^^^^^^^^^^ help: change the return type to: `usize`
4
+ LL | fn boxed_usize () -> Box<usize> {
5
+ | ^^^^^^^^^^ help: change the return type to: `usize`
6
6
|
7
7
= note: `-D clippy::unused-box` implied by `-D warnings`
8
8
9
- error: aborting due to previous error
9
+ error: function returns `Box<Foo>` when `Foo` implements `Sized`
10
+ --> $DIR/unused_box.rs:11:22
11
+ |
12
+ LL | fn boxed_string() -> Box<Foo> {
13
+ | ^^^^^^^^ help: change the return type to: `Foo`
14
+
15
+ error: aborting due to 2 previous errors
10
16
You can’t perform that action at this time.
0 commit comments