Skip to content

Commit b60f08a

Browse files
committed
Add regression test for pattern checks
1 parent d95f6a9 commit b60f08a

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(if_let_guard, let_chains)]
2+
3+
fn main() {
4+
let mut x = Some(String::new());
5+
let ref mut y @ ref mut z = x;
6+
//~^ ERROR: mutable more than once
7+
let Some(ref mut y @ ref mut z) = x else { return };
8+
//~^ ERROR: mutable more than once
9+
if let Some(ref mut y @ ref mut z) = x {}
10+
//~^ ERROR: mutable more than once
11+
if let Some(ref mut y @ ref mut z) = x && true {}
12+
while let Some(ref mut y @ ref mut z) = x {}
13+
//~^ ERROR: mutable more than once
14+
while let Some(ref mut y @ ref mut z) = x && true {}
15+
match x {
16+
ref mut y @ ref mut z => {} //~ ERROR: mutable more than once
17+
}
18+
match () {
19+
() if let Some(ref mut y @ ref mut z) = x => {} //~ ERROR: mutable more than once
20+
_ => {}
21+
}
22+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error: cannot borrow value as mutable more than once at a time
2+
--> $DIR/conflicting_bindings.rs:5:9
3+
|
4+
LL | let ref mut y @ ref mut z = x;
5+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
6+
| |
7+
| value is mutably borrowed by `y` here
8+
9+
error: cannot borrow value as mutable more than once at a time
10+
--> $DIR/conflicting_bindings.rs:7:14
11+
|
12+
LL | let Some(ref mut y @ ref mut z) = x else { return };
13+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
14+
| |
15+
| value is mutably borrowed by `y` here
16+
17+
error: cannot borrow value as mutable more than once at a time
18+
--> $DIR/conflicting_bindings.rs:9:17
19+
|
20+
LL | if let Some(ref mut y @ ref mut z) = x {}
21+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
22+
| |
23+
| value is mutably borrowed by `y` here
24+
25+
error: cannot borrow value as mutable more than once at a time
26+
--> $DIR/conflicting_bindings.rs:12:20
27+
|
28+
LL | while let Some(ref mut y @ ref mut z) = x {}
29+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
30+
| |
31+
| value is mutably borrowed by `y` here
32+
33+
error: cannot borrow value as mutable more than once at a time
34+
--> $DIR/conflicting_bindings.rs:16:9
35+
|
36+
LL | ref mut y @ ref mut z => {}
37+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
38+
| |
39+
| value is mutably borrowed by `y` here
40+
41+
error: cannot borrow value as mutable more than once at a time
42+
--> $DIR/conflicting_bindings.rs:19:24
43+
|
44+
LL | () if let Some(ref mut y @ ref mut z) = x => {}
45+
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
46+
| |
47+
| value is mutably borrowed by `y` here
48+
49+
error: aborting due to 6 previous errors
50+

0 commit comments

Comments
 (0)