Add regression test for pattern checks

This commit is contained in:
Nadrieril 2023-10-29 05:11:52 +01:00
parent d95f6a9532
commit b60f08a66d
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#![feature(if_let_guard, let_chains)]
fn main() {
let mut x = Some(String::new());
let ref mut y @ ref mut z = x;
//~^ ERROR: mutable more than once
let Some(ref mut y @ ref mut z) = x else { return };
//~^ ERROR: mutable more than once
if let Some(ref mut y @ ref mut z) = x {}
//~^ ERROR: mutable more than once
if let Some(ref mut y @ ref mut z) = x && true {}
while let Some(ref mut y @ ref mut z) = x {}
//~^ ERROR: mutable more than once
while let Some(ref mut y @ ref mut z) = x && true {}
match x {
ref mut y @ ref mut z => {} //~ ERROR: mutable more than once
}
match () {
() if let Some(ref mut y @ ref mut z) = x => {} //~ ERROR: mutable more than once
_ => {}
}
}

View File

@ -0,0 +1,50 @@
error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:5:9
|
LL | let ref mut y @ ref mut z = x;
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here
error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:7:14
|
LL | let Some(ref mut y @ ref mut z) = x else { return };
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here
error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:9:17
|
LL | if let Some(ref mut y @ ref mut z) = x {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here
error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:12:20
|
LL | while let Some(ref mut y @ ref mut z) = x {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here
error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:16:9
|
LL | ref mut y @ ref mut z => {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here
error: cannot borrow value as mutable more than once at a time
--> $DIR/conflicting_bindings.rs:19:24
|
LL | () if let Some(ref mut y @ ref mut z) = x => {}
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
| |
| value is mutably borrowed by `y` here
error: aborting due to 6 previous errors