]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-multiple-captures.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-multiple-captures.rs
1 use std::thread;
2
3
4 fn borrow<T>(_: &T) { }
5
6
7 fn different_vars_after_borrows() {
8     let x1: Box<_> = Box::new(1);
9     let p1 = &x1;
10     let x2: Box<_> = Box::new(2);
11     let p2 = &x2;
12     thread::spawn(move|| {
13         //~^ ERROR cannot move out of `x1` because it is borrowed
14         //~| ERROR cannot move out of `x2` because it is borrowed
15         drop(x1);
16         drop(x2);
17     });
18     borrow(&*p1);
19     borrow(&*p2);
20 }
21
22 fn different_vars_after_moves() {
23     let x1: Box<_> = Box::new(1);
24     drop(x1);
25     let x2: Box<_> = Box::new(2);
26     drop(x2);
27     thread::spawn(move|| {
28         //~^ ERROR use of moved value: `x1`
29         //~| ERROR use of moved value: `x2`
30         drop(x1);
31         drop(x2);
32     });
33 }
34
35 fn same_var_after_borrow() {
36     let x: Box<_> = Box::new(1);
37     let p = &x;
38     thread::spawn(move|| {
39         //~^ ERROR cannot move out of `x` because it is borrowed
40         drop(x);
41         drop(x); //~ ERROR use of moved value: `x`
42     });
43     borrow(&*p);
44 }
45
46 fn same_var_after_move() {
47     let x: Box<_> = Box::new(1);
48     drop(x);
49     thread::spawn(move|| {
50         //~^ ERROR use of moved value: `x`
51         drop(x);
52         drop(x); //~ ERROR use of moved value: `x`
53     });
54 }
55
56 fn main() {
57     different_vars_after_borrows();
58     different_vars_after_moves();
59     same_var_after_borrow();
60     same_var_after_move();
61 }