Skip to content

Commit bb014f7

Browse files
committed
Added more tests
1 parent 3340b68 commit bb014f7

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

tests/ui/unused_box.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
#![warn(clippy::unused_box)]
22

3-
fn foo() -> Box<usize> {
3+
struct Foo {}
4+
5+
// lint
6+
fn boxed_usize() -> Box<usize> {
47
Box::new(5)
58
}
69

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+
728
fn main() {
8-
// test code goes here
29+
// don't lint: this is a closure
30+
let a = || -> Box<usize> { Box::new(5) };
931
}

tests/ui/unused_box.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
error: function returns `Box<usize>` when `usize` implements `Sized`
2-
--> $DIR/unused_box.rs:3:13
2+
--> $DIR/unused_box.rs:6:21
33
|
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`
66
|
77
= note: `-D clippy::unused-box` implied by `-D warnings`
88

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
1016

0 commit comments

Comments
 (0)