]> git.proxmox.com Git - rustc.git/blob - tests/ui/unboxed-closures/unboxed-closures-move-some-upvars-in-by-ref-closure.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / unboxed-closures / unboxed-closures-move-some-upvars-in-by-ref-closure.rs
1 // run-pass
2 // Test that in a by-ref once closure we move some variables even as
3 // we capture others by mutable reference.
4
5 fn call<F>(f: F) where F : FnOnce() {
6 f();
7 }
8
9 fn main() {
10 let mut x = vec![format!("Hello")];
11 let y = vec![format!("World")];
12 call(|| {
13 // Here: `x` must be captured with a mutable reference in
14 // order for us to append on it, and `y` must be captured by
15 // value.
16 for item in y {
17 x.push(item);
18 }
19 });
20 assert_eq!(x.len(), 2);
21 assert_eq!(&*x[0], "Hello");
22 assert_eq!(&*x[1], "World");
23 }