diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/borrowck/borrowck-multiple-captures.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/borrowck/borrowck-multiple-captures.rs')
-rw-r--r-- | src/test/ui/borrowck/borrowck-multiple-captures.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/borrowck-multiple-captures.rs b/src/test/ui/borrowck/borrowck-multiple-captures.rs new file mode 100644 index 000000000..57b3819ac --- /dev/null +++ b/src/test/ui/borrowck/borrowck-multiple-captures.rs @@ -0,0 +1,61 @@ +use std::thread; + + +fn borrow<T>(_: &T) { } + + +fn different_vars_after_borrows() { + let x1: Box<_> = Box::new(1); + let p1 = &x1; + let x2: Box<_> = Box::new(2); + let p2 = &x2; + thread::spawn(move|| { + //~^ ERROR cannot move out of `x1` because it is borrowed + //~| ERROR cannot move out of `x2` because it is borrowed + drop(x1); + drop(x2); + }); + borrow(&*p1); + borrow(&*p2); +} + +fn different_vars_after_moves() { + let x1: Box<_> = Box::new(1); + drop(x1); + let x2: Box<_> = Box::new(2); + drop(x2); + thread::spawn(move|| { + //~^ ERROR use of moved value: `x1` + //~| ERROR use of moved value: `x2` + drop(x1); + drop(x2); + }); +} + +fn same_var_after_borrow() { + let x: Box<_> = Box::new(1); + let p = &x; + thread::spawn(move|| { + //~^ ERROR cannot move out of `x` because it is borrowed + drop(x); + drop(x); //~ ERROR use of moved value: `x` + }); + borrow(&*p); +} + +fn same_var_after_move() { + let x: Box<_> = Box::new(1); + drop(x); + thread::spawn(move|| { + //~^ ERROR use of moved value: `x` + drop(x); + 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(); +} |