diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2020-03-05 14:06:40 -0500 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-04-10 18:07:56 +0200 |
| commit | 1ff99b724ccafc5d0077827f6913f825be042949 (patch) | |
| tree | 79bf2c6126c96f6c9fe4900c96a6d2c12fc44a05 /src/test/ui/binding | |
| parent | 192d5330c40ea8ac4e3f3462c47c7cbe9b293ec9 (diff) | |
| download | rust-1ff99b724ccafc5d0077827f6913f825be042949.tar.gz rust-1ff99b724ccafc5d0077827f6913f825be042949.zip | |
copy test cases to `if let` as well.
Diffstat (limited to 'src/test/ui/binding')
| -rw-r--r-- | src/test/ui/binding/issue-53114-borrow-checks.rs | 28 | ||||
| -rw-r--r-- | src/test/ui/binding/issue-53114-borrow-checks.stderr | 33 |
2 files changed, 59 insertions, 2 deletions
diff --git a/src/test/ui/binding/issue-53114-borrow-checks.rs b/src/test/ui/binding/issue-53114-borrow-checks.rs index 2eb11ed84d4..7646472f45f 100644 --- a/src/test/ui/binding/issue-53114-borrow-checks.rs +++ b/src/test/ui/binding/issue-53114-borrow-checks.rs @@ -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() { @@ -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; @@ -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() { } diff --git a/src/test/ui/binding/issue-53114-borrow-checks.stderr b/src/test/ui/binding/issue-53114-borrow-checks.stderr index 18114dc09cf..f535a66cf63 100644 --- a/src/test/ui/binding/issue-53114-borrow-checks.stderr +++ b/src/test/ui/binding/issue-53114-borrow-checks.stderr @@ -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`. |
