Skip to content

Commit 1ff99b7

Browse files
pnkfelixCentril
authored andcommitted
copy test cases to if let as well.
1 parent 192d533 commit 1ff99b7

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/test/ui/binding/issue-53114-borrow-checks.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// checker, and both had some deviations from our ideal state. This test
33
// captures the behavior of how `_` bindings are handled with respect to how we
44
// flag expressions that are meant to request unsafe blocks.
5-
5+
#![allow(irrefutable_let_patterns)]
66
struct M;
77

88
fn let_wild_gets_moved_expr() {
@@ -30,6 +30,20 @@ fn match_moved_expr_to_wild() {
3030
//~^ ERROR [E0382]
3131
}
3232

33+
fn if_let_moved_expr_to_wild() {
34+
let m = M;
35+
drop(m);
36+
if let _ = m { } // #53114: should eventually be accepted too
37+
//~^ ERROR [E0382]
38+
39+
let mm = (M, M); // variation on above with `_` in substructure
40+
if let (_x, _) = mm { }
41+
if let (_, _y) = mm { }
42+
//~^ ERROR [E0382]
43+
if let (_, _) = mm { }
44+
//~^ ERROR [E0382]
45+
}
46+
3347
fn let_wild_gets_borrowed_expr() {
3448
let mut m = M;
3549
let r = &mut m;
@@ -55,4 +69,16 @@ fn match_borrowed_expr_to_wild() {
5569
drop((r1, r2));
5670
}
5771

72+
fn if_let_borrowed_expr_to_wild() {
73+
let mut m = M;
74+
let r = &mut m;
75+
if let _ = m { } // accepted, and want it to continue to be
76+
drop(r);
77+
78+
let mut mm = (M, M); // variation on above with `_` in substructure
79+
let (r1, r2) = (&mut mm.0, &mut mm.1);
80+
if let (_, _) = mm { }
81+
drop((r1, r2));
82+
}
83+
5884
fn main() { }

src/test/ui/binding/issue-53114-borrow-checks.stderr

+32-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,37 @@ LL | match mm { (_, _) => { } }
2929
|
3030
= note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait
3131

32-
error: aborting due to 3 previous errors
32+
error[E0382]: use of moved value: `m`
33+
--> $DIR/issue-53114-borrow-checks.rs:36:16
34+
|
35+
34 | let m = M;
36+
| - move occurs because `m` has type `M`, which does not implement the `Copy` trait
37+
35 | drop(m);
38+
| - value moved here
39+
36 | if let _ = m { } // #53114: should eventually be accepted too
40+
| ^ value used here after move
41+
42+
error[E0382]: use of moved value: `mm`
43+
--> $DIR/issue-53114-borrow-checks.rs:41:22
44+
|
45+
40 | if let (_x, _) = mm { }
46+
| -- value moved here
47+
41 | if let (_, _y) = mm { }
48+
| ^^ value used here after partial move
49+
|
50+
= note: move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait
51+
52+
error[E0382]: use of moved value: `mm`
53+
--> $DIR/issue-53114-borrow-checks.rs:43:21
54+
|
55+
41 | if let (_, _y) = mm { }
56+
| -- value moved here
57+
42 |
58+
43 | if let (_, _) = mm { }
59+
| ^^ value used here after partial move
60+
|
61+
= note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait
62+
63+
error: aborting due to 6 previous errors
3364

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

0 commit comments

Comments
 (0)