3 // Exercise the unused_mut attribute in some positive and negative cases
6 #![feature(async_closure, raw_ref_op)]
10 //~^ WARN: variable does not need to be mutable
11 #[allow(unused_mut)] mut b: i32,
15 //~^ WARN: variable does not need to be mutable
16 #[allow(unused_mut)] mut b: i32,
17 #[allow(unused_mut)] (mut c, d): (i32, i32)
24 //~^ WARN: variable does not need to be mutable
25 #[allow(unused_mut)] mut b: i32,
30 //~^ WARN: variable does not need to be mutable
31 #[allow(unused_mut)] mut b: i32,
32 #[allow(unused_mut)] (mut c, d): (i32, i32)
40 //~^ WARN: variable does not need to be mutable
41 #[allow(unused_mut)] mut b: i32,
42 #[allow(unused_mut)] (mut c, d): (i32, i32)
45 impl RefTrait for () {
49 //~^ WARN: variable does not need to be mutable
50 #[allow(unused_mut)] mut b: i32,
51 #[allow(unused_mut)] (mut c, d): (i32, i32)
58 //~^ WARN: variable does not need to be mutable
59 #[allow(unused_mut)] mut b: i32,
63 //~^ WARN: variable does not need to be mutable
64 #[allow(unused_mut)] mut b: i32,
65 #[allow(unused_mut)] (mut c, d): (i32, i32)
69 let mut a = 3; //~ WARN: variable does not need to be mutable
71 let mut a = 2; //~ WARN: variable does not need to be mutable
73 let mut b = 3; //~ WARN: variable does not need to be mutable
75 let mut a = vec![3]; //~ WARN: variable does not need to be mutable
77 let (mut a, b) = (1, 2); //~ WARN: variable does not need to be mutable
79 let mut a; //~ WARN: variable does not need to be mutable
83 let mut b; //~ WARN: variable does not need to be mutable
92 mut x => {} //~ WARN: variable does not need to be mutable
97 // FIXME: Here's a false positive,
98 // shouldn't be removed `mut` not to be bound with a different way.
99 (mut x, 1) | //~ WARN: variable does not need to be mutable
107 let x = |mut y: isize| 10; //~ WARN: variable does not need to be mutable
109 fn what(mut foo: isize) {} //~ WARN: variable does not need to be mutable
112 let mut a = &mut 5; //~ WARN: variable does not need to be mutable
117 let mut b = (&mut a,); //~ WARN: variable does not need to be mutable
120 let mut x = &mut 1; //~ WARN: variable does not need to be mutable
127 fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] {
128 &mut arg[..] //~^ WARN: variable does not need to be mutable
132 let mut v : &mut Vec<()> = &mut vec![]; //~ WARN: variable does not need to be mutable
139 let mut a = Vec::new();
141 let mut a = Vec::new();
145 let mut a = Vec::new();
151 let (mut a, b) = (1, 2);
169 // Attribute should be respected on match arms
177 let x = |mut y: isize| y = 32;
178 fn nothing(mut foo: isize) { foo = 37; }
180 // leading underscore should avoid the warning, just like the
181 // unused variable lint.
182 let mut _allowed = 1;
184 let mut raw_address_of_mut = 1; // OK
185 let mut_ptr = &raw mut raw_address_of_mut;
187 let mut raw_address_of_const = 1; //~ WARN: variable does not need to be mutable
188 let const_ptr = &raw const raw_address_of_const;
191 fn callback<F>(f: F) where F: FnOnce() {}
193 // make sure the lint attribute can be turned off
195 fn foo(mut a: isize) {
200 // make sure the lint attribute can be turned off on let statements
205 let mut b = vec![2]; //~ ERROR: variable does not need to be mutable