1 // Exercise the unused_mut attribute in some positive and negative cases
3 #![allow(unused_assignments)]
4 #![allow(unused_variables)]
11 let mut a = 3; //~ ERROR: variable does not need to be mutable
13 let mut a = 2; //~ ERROR: variable does not need to be mutable
15 let mut b = 3; //~ ERROR: variable does not need to be mutable
17 let mut a = vec![3]; //~ ERROR: variable does not need to be mutable
19 let (mut a, b) = (1, 2); //~ ERROR: variable does not need to be mutable
21 let mut a; //~ ERROR: variable does not need to be mutable
25 let mut b; //~ ERROR: variable does not need to be mutable
34 mut x => {} //~ ERROR: variable does not need to be mutable
38 (mut x, 1) | //~ ERROR: variable does not need to be mutable
46 let x = |mut y: isize| 10; //~ ERROR: variable does not need to be mutable
48 fn what(mut foo: isize) {} //~ ERROR: variable does not need to be mutable
51 let mut a = &mut 5; //~ ERROR: variable does not need to be mutable
56 let mut b = (&mut a,); //~ ERROR: variable does not need to be mutable
59 let mut x = &mut 1; //~ ERROR: variable does not need to be mutable
66 fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] {
67 &mut arg[..] //~^ ERROR: variable does not need to be mutable
71 let mut v : &mut Vec<()> = &mut vec![]; //~ ERROR: variable does not need to be mutable
78 let mut a = Vec::new();
80 let mut a = Vec::new();
84 let mut a = Vec::new();
90 let (mut a, b) = (1, 2);
108 // Attribute should be respected on match arms
116 let x = |mut y: isize| y = 32;
117 fn nothing(mut foo: isize) { foo = 37; }
119 // leading underscore should avoid the warning, just like the
120 // unused variable lint.
121 let mut _allowed = 1;
124 fn callback<F>(f: F) where F: FnOnce() {}
126 // make sure the lint attribute can be turned off
128 fn foo(mut a: isize) {
133 // make sure the lint attribute can be turned off on let statements
138 let mut b = vec![2]; //~ ERROR: variable does not need to be mutable