Skip to content

Commit 427d915

Browse files
committed
Also check if let chains with multiple lets in these two tests
1 parent ec239b8 commit 427d915

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

Diff for: tests/ui/pattern/usefulness/conflicting_bindings.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ fn main() {
1010
//~^ ERROR: mutable more than once
1111
if let Some(ref mut y @ ref mut z) = x && true {}
1212
//~^ ERROR: mutable more than once
13+
if let Some(_) = Some(()) && let Some(ref mut y @ ref mut z) = x && true {}
14+
//~^ ERROR: mutable more than once
1315
while let Some(ref mut y @ ref mut z) = x {}
1416
//~^ ERROR: mutable more than once
1517
while let Some(ref mut y @ ref mut z) = x && true {}

Diff for: tests/ui/pattern/usefulness/conflicting_bindings.stderr

+13-5
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,44 @@ LL | if let Some(ref mut y @ ref mut z) = x && true {}
3131
| value is mutably borrowed by `y` here
3232

3333
error: cannot borrow value as mutable more than once at a time
34-
--> $DIR/conflicting_bindings.rs:13:20
34+
--> $DIR/conflicting_bindings.rs:13:43
35+
|
36+
LL | if let Some(_) = Some(()) && let Some(ref mut y @ ref mut z) = x && true {}
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:15:20
3543
|
3644
LL | while let Some(ref mut y @ ref mut z) = x {}
3745
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
3846
| |
3947
| value is mutably borrowed by `y` here
4048

4149
error: cannot borrow value as mutable more than once at a time
42-
--> $DIR/conflicting_bindings.rs:15:20
50+
--> $DIR/conflicting_bindings.rs:17:20
4351
|
4452
LL | while let Some(ref mut y @ ref mut z) = x && true {}
4553
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
4654
| |
4755
| value is mutably borrowed by `y` here
4856

4957
error: cannot borrow value as mutable more than once at a time
50-
--> $DIR/conflicting_bindings.rs:18:9
58+
--> $DIR/conflicting_bindings.rs:20:9
5159
|
5260
LL | ref mut y @ ref mut z => {}
5361
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
5462
| |
5563
| value is mutably borrowed by `y` here
5664

5765
error: cannot borrow value as mutable more than once at a time
58-
--> $DIR/conflicting_bindings.rs:21:24
66+
--> $DIR/conflicting_bindings.rs:23:24
5967
|
6068
LL | () if let Some(ref mut y @ ref mut z) = x => {}
6169
| ^^^^^^^^^ --------- value is mutably borrowed by `z` here
6270
| |
6371
| value is mutably borrowed by `y` here
6472

65-
error: aborting due to 8 previous errors
73+
error: aborting due to 9 previous errors
6674

Diff for: tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.rs

+11
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,15 @@ fn use_in_arm_ok(c: bool) {
9494
};
9595
}
9696

97+
fn use_in_same_chain(c: bool) {
98+
let x: Box<_> = Box::new(1);
99+
100+
let v = (1, 2);
101+
102+
match v {
103+
(1, 2) if let y = x && c && let z = x => false, //~ ERROR use of moved value: `x`
104+
_ => true,
105+
};
106+
}
107+
97108
fn main() {}

Diff for: tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ help: borrow this binding in the pattern to avoid moving the value
6060
LL | (1, 2) if let ref y = x && c => false,
6161
| +++
6262

63-
error: aborting due to 4 previous errors
63+
error[E0382]: use of moved value: `x`
64+
--> $DIR/move-guard-if-let-chain.rs:103:41
65+
|
66+
LL | let x: Box<_> = Box::new(1);
67+
| - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
68+
...
69+
LL | (1, 2) if let y = x && c && let z = x => false,
70+
| - ^ value used here after move
71+
| |
72+
| value moved here
73+
|
74+
help: borrow this binding in the pattern to avoid moving the value
75+
|
76+
LL | (1, 2) if let ref y = x && c && let z = x => false,
77+
| +++
78+
79+
error: aborting due to 5 previous errors
6480

6581
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)