mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Add regression test for pattern checks
This commit is contained in:
parent
d95f6a9532
commit
b60f08a66d
22
tests/ui/pattern/usefulness/conflicting_bindings.rs
Normal file
22
tests/ui/pattern/usefulness/conflicting_bindings.rs
Normal 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
|
||||
_ => {}
|
||||
}
|
||||
}
|
50
tests/ui/pattern/usefulness/conflicting_bindings.stderr
Normal file
50
tests/ui/pattern/usefulness/conflicting_bindings.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user