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-vec-pattern-nesting.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-vec-pattern-nesting.rs')
-rw-r--r-- | src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs new file mode 100644 index 000000000..8a9296c59 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs @@ -0,0 +1,94 @@ +#![feature(box_patterns)] + + +fn a() { + let mut vec = [Box::new(1), Box::new(2), Box::new(3)]; + match vec { + [box ref _a, _, _] => { + //~^ NOTE borrow of `vec[_]` occurs here + vec[0] = Box::new(4); //~ ERROR cannot assign + //~^ NOTE assignment to borrowed `vec[_]` occurs here + _a.use_ref(); + //~^ NOTE borrow later used here + } + } +} + +fn b() { + let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)]; + let vec: &mut [Box<isize>] = &mut vec; + match vec { + &mut [ref _b @ ..] => { + //~^ borrow of `vec[_]` occurs here + vec[0] = Box::new(4); //~ ERROR cannot assign + //~^ NOTE assignment to borrowed `vec[_]` occurs here + _b.use_ref(); + //~^ NOTE borrow later used here + } + } +} + +fn c() { + let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)]; + let vec: &mut [Box<isize>] = &mut vec; + match vec { + //~^ ERROR cannot move out + //~| NOTE cannot move out + &mut [_a, + //~^ NOTE data moved here + //~| NOTE move occurs because `_a` has type + //~| HELP consider removing the `&mut` + .. + ] => { + } + _ => {} + } + let a = vec[0]; //~ ERROR cannot move out + //~| NOTE cannot move out of here + //~| NOTE move occurs because + //~| HELP consider borrowing here +} + +fn d() { + let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)]; + let vec: &mut [Box<isize>] = &mut vec; + match vec { + //~^ ERROR cannot move out + //~| NOTE cannot move out + &mut [ + //~^ HELP consider removing the `&mut` + _b] => {} + //~^ NOTE data moved here + //~| NOTE move occurs because `_b` has type + _ => {} + } + let a = vec[0]; //~ ERROR cannot move out + //~| NOTE cannot move out of here + //~| NOTE move occurs because + //~| HELP consider borrowing here +} + +fn e() { + let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)]; + let vec: &mut [Box<isize>] = &mut vec; + match vec { + //~^ ERROR cannot move out + //~| NOTE cannot move out + //~| NOTE move occurs because these variables have types + &mut [_a, _b, _c] => {} + //~^ NOTE data moved here + //~| NOTE and here + //~| NOTE and here + //~| HELP consider removing the `&mut` + _ => {} + } + let a = vec[0]; //~ ERROR cannot move out + //~| NOTE cannot move out of here + //~| NOTE move occurs because + //~| HELP consider borrowing here +} + +fn main() {} + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl<T> Fake for T { } |