2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2015-01-24 22:25:07 +00:00
|
|
|
// Test that in a by-ref once closure we move some variables even as
|
|
|
|
// we capture others by mutable reference.
|
|
|
|
|
|
|
|
fn call<F>(f: F) where F : FnOnce() {
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2016-10-29 21:54:04 +00:00
|
|
|
let mut x = vec![format!("Hello")];
|
|
|
|
let y = vec![format!("World")];
|
2015-01-24 22:25:07 +00:00
|
|
|
call(|| {
|
|
|
|
// Here: `x` must be captured with a mutable reference in
|
|
|
|
// order for us to append on it, and `y` must be captured by
|
|
|
|
// value.
|
2015-02-01 01:03:04 +00:00
|
|
|
for item in y {
|
2015-01-24 22:25:07 +00:00
|
|
|
x.push(item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert_eq!(x.len(), 2);
|
|
|
|
assert_eq!(&*x[0], "Hello");
|
|
|
|
assert_eq!(&*x[1], "World");
|
|
|
|
}
|