From cf2dff2b1e3fa55fa5415d524200070d0d7aacfe Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Thu, 5 Jan 2023 09:13:28 +0100 Subject: Move /src/test to /tests --- tests/ui/borrowck/borrowck-vec-pattern-nesting.rs | 94 +++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/ui/borrowck/borrowck-vec-pattern-nesting.rs (limited to 'tests/ui/borrowck/borrowck-vec-pattern-nesting.rs') diff --git a/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs b/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs new file mode 100644 index 00000000000..0e9284a2cad --- /dev/null +++ b/tests/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] = &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] = &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 mutable borrow + .. + ] => { + } + _ => {} + } + 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] = &mut vec; + match vec { + //~^ ERROR cannot move out + //~| NOTE cannot move out + &mut [ + //~^ HELP consider removing the mutable borrow + _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] = &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 mutable borrow + _ => {} + } + 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 Fake for T { } -- cgit 1.4.1-3-g733a5