Skip to content

Commit

Permalink
copy test cases to if let as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix authored and Centril committed Apr 10, 2020
1 parent 192d533 commit 1ff99b7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/test/ui/binding/issue-53114-borrow-checks.rs
Expand Up @@ -2,7 +2,7 @@
// checker, and both had some deviations from our ideal state. This test
// captures the behavior of how `_` bindings are handled with respect to how we
// flag expressions that are meant to request unsafe blocks.

#![allow(irrefutable_let_patterns)]
struct M;

fn let_wild_gets_moved_expr() {
Expand Down Expand Up @@ -30,6 +30,20 @@ fn match_moved_expr_to_wild() {
//~^ ERROR [E0382]
}

fn if_let_moved_expr_to_wild() {
let m = M;
drop(m);
if let _ = m { } // #53114: should eventually be accepted too
//~^ ERROR [E0382]

let mm = (M, M); // variation on above with `_` in substructure
if let (_x, _) = mm { }
if let (_, _y) = mm { }
//~^ ERROR [E0382]
if let (_, _) = mm { }
//~^ ERROR [E0382]
}

fn let_wild_gets_borrowed_expr() {
let mut m = M;
let r = &mut m;
Expand All @@ -55,4 +69,16 @@ fn match_borrowed_expr_to_wild() {
drop((r1, r2));
}

fn if_let_borrowed_expr_to_wild() {
let mut m = M;
let r = &mut m;
if let _ = m { } // accepted, and want it to continue to be
drop(r);

let mut mm = (M, M); // variation on above with `_` in substructure
let (r1, r2) = (&mut mm.0, &mut mm.1);
if let (_, _) = mm { }
drop((r1, r2));
}

fn main() { }
33 changes: 32 additions & 1 deletion src/test/ui/binding/issue-53114-borrow-checks.stderr
Expand Up @@ -29,6 +29,37 @@ LL | match mm { (_, _) => { } }
|
= note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait

error: aborting due to 3 previous errors
error[E0382]: use of moved value: `m`
--> $DIR/issue-53114-borrow-checks.rs:36:16
|
34 | let m = M;
| - move occurs because `m` has type `M`, which does not implement the `Copy` trait
35 | drop(m);
| - value moved here
36 | if let _ = m { } // #53114: should eventually be accepted too
| ^ value used here after move

error[E0382]: use of moved value: `mm`
--> $DIR/issue-53114-borrow-checks.rs:41:22
|
40 | if let (_x, _) = mm { }
| -- value moved here
41 | if let (_, _y) = mm { }
| ^^ value used here after partial move
|
= note: move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait

error[E0382]: use of moved value: `mm`
--> $DIR/issue-53114-borrow-checks.rs:43:21
|
41 | if let (_, _y) = mm { }
| -- value moved here
42 |
43 | if let (_, _) = mm { }
| ^^ value used here after partial move
|
= note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait

error: aborting due to 6 previous errors

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

0 comments on commit 1ff99b7

Please sign in to comment.