Skip to content

Commit 37c193a

Browse files
committed
Add test for unused_allocation
Before the unused_allocation lint has never been tested outside of its lint documentation.
1 parent 7ca8ff0 commit 37c193a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(box_syntax)]
2+
#![deny(unused_allocation)]
3+
4+
fn main() {
5+
let foo = (box [1, 2, 3]).len(); //~ ERROR: unnecessary allocation
6+
let one = (box vec![1]).pop(); //~ ERROR: unnecessary allocation
7+
8+
let foo = Box::new([1, 2, 3]).len(); //~ ERROR: unnecessary allocation
9+
let one = Box::new(vec![1]).pop(); //~ ERROR: unnecessary allocation
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: unnecessary allocation, use `&` instead
2+
--> $DIR/unused-allocation.rs:5:15
3+
|
4+
LL | let foo = (box [1, 2, 3]).len();
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused-allocation.rs:2:9
9+
|
10+
LL | #![deny(unused_allocation)]
11+
| ^^^^^^^^^^^^^^^^^
12+
13+
error: unnecessary allocation, use `&mut` instead
14+
--> $DIR/unused-allocation.rs:6:15
15+
|
16+
LL | let one = (box vec![1]).pop();
17+
| ^^^^^^^^^^^^^
18+
19+
error: unnecessary allocation, use `&` instead
20+
--> $DIR/unused-allocation.rs:8:15
21+
|
22+
LL | let foo = Box::new([1, 2, 3]).len();
23+
| ^^^^^^^^
24+
25+
error: unnecessary allocation, use `&mut` instead
26+
--> $DIR/unused-allocation.rs:9:15
27+
|
28+
LL | let one = Box::new(vec![1]).pop();
29+
| ^^^^^^^^
30+
31+
error: aborting due to 4 previous errors
32+

0 commit comments

Comments
 (0)