1 // run-pass 2 // Test that we mutate a counter on the stack only when we expect to. 3 call<F>(f: F) where F : FnOnce()4fn call<F>(f: F) where F : FnOnce() { 5 f(); 6 } 7 main()8fn main() { 9 let y = vec![format!("Hello"), format!("World")]; 10 let mut counter = 22_u32; 11 12 call(|| { 13 // Move `y`, but do not move `counter`, even though it is read 14 // by value (note that it is also mutated). 15 for item in y { //~ WARN unused variable: `item` 16 let v = counter; 17 counter += v; 18 } 19 }); 20 assert_eq!(counter, 88); 21 22 call(move || { 23 // this mutates a moved copy, and hence doesn't affect original 24 counter += 1; //~ WARN value assigned to `counter` is never read 25 //~| WARN unused variable: `counter` 26 }); 27 assert_eq!(counter, 88); 28 } 29