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
96 (mut x, 1) | //~ WARN: variable does not need to be mutable
104 let x = |mut y: isize| 10; //~ WARN: variable does not need to be mutable
106 fn what(mut foo: isize) {} //~ WARN: variable does not need to be mutable
109 let mut a = &mut 5; //~ WARN: variable does not need to be mutable
114 let mut b = (&mut a,); //~ WARN: variable does not need to be mutable
117 let mut x = &mut 1; //~ WARN: variable does not need to be mutable
124 fn mut_ref_arg(mut arg : &mut [u8]) -> &mut [u8] {
125 &mut arg[..] //~^ WARN: variable does not need to be mutable
129 let mut v : &mut Vec<()> = &mut vec![]; //~ WARN: variable does not need to be mutable
136 let mut a = Vec::new();
138 let mut a = Vec::new();
142 let mut a = Vec::new();
148 let (mut a, b) = (1, 2);
166 // Attribute should be respected on match arms
174 let x = |mut y: isize| y = 32;
175 fn nothing(mut foo: isize) { foo = 37; }
177 // leading underscore should avoid the warning, just like the
178 // unused variable lint.
179 let mut _allowed = 1;
181 let mut raw_address_of_mut = 1; // OK
182 let mut_ptr = &raw mut raw_address_of_mut;
184 let mut raw_address_of_const = 1; //~ WARN: variable does not need to be mutable
185 let const_ptr = &raw const raw_address_of_const;
188 fn callback<F>(f: F) where F: FnOnce() {}
190 // make sure the lint attribute can be turned off
192 fn foo(mut a: isize) {
197 // make sure the lint attribute can be turned off on let statements
202 let mut b = vec![2]; //~ ERROR: variable does not need to be mutable