2015-02-17 17:10:25 -06:00
|
|
|
use std::thread;
|
2014-06-06 13:59:33 -05:00
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
fn borrow<T>(_: &T) { }
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
2014-06-06 13:59:33 -05:00
|
|
|
fn different_vars_after_borrows() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x1: Box<_> = Box::new(1);
|
2014-06-06 13:59:33 -05:00
|
|
|
let p1 = &x1;
|
2021-08-24 19:39:40 -05:00
|
|
|
let x2: Box<_> = Box::new(2);
|
2014-06-06 13:59:33 -05:00
|
|
|
let p2 = &x2;
|
2015-02-17 17:10:25 -06:00
|
|
|
thread::spawn(move|| {
|
2019-04-22 02:40:08 -05:00
|
|
|
//~^ ERROR cannot move out of `x1` because it is borrowed
|
|
|
|
//~| ERROR cannot move out of `x2` because it is borrowed
|
|
|
|
drop(x1);
|
|
|
|
drop(x2);
|
2014-06-06 13:59:33 -05:00
|
|
|
});
|
|
|
|
borrow(&*p1);
|
|
|
|
borrow(&*p2);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn different_vars_after_moves() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x1: Box<_> = Box::new(1);
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x1);
|
2021-08-24 19:39:40 -05:00
|
|
|
let x2: Box<_> = Box::new(2);
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x2);
|
2015-02-17 17:10:25 -06:00
|
|
|
thread::spawn(move|| {
|
2019-04-22 02:40:08 -05:00
|
|
|
//~^ ERROR use of moved value: `x1`
|
|
|
|
//~| ERROR use of moved value: `x2`
|
|
|
|
drop(x1);
|
|
|
|
drop(x2);
|
2014-06-06 13:59:33 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn same_var_after_borrow() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x: Box<_> = Box::new(1);
|
2014-06-06 13:59:33 -05:00
|
|
|
let p = &x;
|
2015-02-17 17:10:25 -06:00
|
|
|
thread::spawn(move|| {
|
2019-04-22 02:40:08 -05:00
|
|
|
//~^ ERROR cannot move out of `x` because it is borrowed
|
|
|
|
drop(x);
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x); //~ ERROR use of moved value: `x`
|
|
|
|
});
|
|
|
|
borrow(&*p);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn same_var_after_move() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let x: Box<_> = Box::new(1);
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x);
|
2015-02-17 17:10:25 -06:00
|
|
|
thread::spawn(move|| {
|
2019-04-22 02:40:08 -05:00
|
|
|
//~^ ERROR use of moved value: `x`
|
|
|
|
drop(x);
|
2014-06-06 13:59:33 -05:00
|
|
|
drop(x); //~ ERROR use of moved value: `x`
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
different_vars_after_borrows();
|
|
|
|
different_vars_after_moves();
|
|
|
|
same_var_after_borrow();
|
|
|
|
same_var_after_move();
|
|
|
|
}
|