Skip to content

Commit 52aee99

Browse files
Add test for unnecessary mut passed lint
1 parent 33a0799 commit 52aee99

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/compile-fail/mut_reference.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#![feature(plugin)]
2+
#![plugin(clippy)]
3+
4+
fn takes_an_immutable_reference(a: &i32) {
5+
}
6+
7+
fn takes_a_mutable_reference(a: &mut i32) {
8+
}
9+
10+
struct MyStruct;
11+
12+
impl MyStruct {
13+
fn takes_an_immutable_reference(&self, a: &i32) {
14+
}
15+
16+
fn takes_a_mutable_reference(&self, a: &mut i32) {
17+
}
18+
}
19+
20+
#[deny(unnecessary_mut_passed)]
21+
fn main() {
22+
// Functions
23+
takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
24+
25+
// Methods
26+
let my_struct = MyStruct;
27+
my_struct.takes_an_immutable_reference(&mut 42); //~ERROR The function/method "takes_an_immutable_reference" doesn't need a mutable reference
28+
29+
30+
// No error
31+
32+
// Functions
33+
takes_an_immutable_reference(&42);
34+
takes_a_mutable_reference(&mut 42);
35+
let mut a = &mut 42;
36+
takes_an_immutable_reference(a);
37+
38+
// Methods
39+
my_struct.takes_an_immutable_reference(&42);
40+
my_struct.takes_a_mutable_reference(&mut 42);
41+
my_struct.takes_an_immutable_reference(a);
42+
43+
}

0 commit comments

Comments
 (0)