]> git.proxmox.com Git - rustc.git/blame - src/test/ui/unboxed-closures/unboxed-closures-counter-not-moved.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / unboxed-closures / unboxed-closures-counter-not-moved.rs
CommitLineData
b7449926 1// run-pass
85aaf69f
SL
2// Test that we mutate a counter on the stack only when we expect to.
3
4fn call<F>(f: F) where F : FnOnce() {
5 f();
6}
7
8fn main() {
c30ab7b3 9 let y = vec![format!("Hello"), format!("World")];
85aaf69f
SL
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).
f9f354fc 15 for item in y { //~ WARN unused variable: `item`
85aaf69f
SL
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
f9f354fc
XL
24 counter += 1; //~ WARN value assigned to `counter` is never read
25 //~| WARN unused variable: `counter`
85aaf69f
SL
26 });
27 assert_eq!(counter, 88);
28}