forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for rust-lang#27282, rust-lang#31287 as hard errors.
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fn main() { | ||
match Some(&4) { | ||
None => {}, | ||
ref mut foo | ||
if { | ||
(|| { let bar = foo; bar.take() })(); | ||
//~^ ERROR cannot move out of `foo` in pattern guard | ||
false | ||
} => {}, | ||
Some(ref _s) => println!("Note this arm is bogus; the `Some` became `None` in the guard."), | ||
_ => println!("Here is some supposedly unreachable code."), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0507]: cannot move out of `foo` in pattern guard | ||
--> $DIR/issue-27282-mutation-in-guard.rs:6:18 | ||
| | ||
LL | (|| { let bar = foo; bar.take() })(); | ||
| ^^ --- | ||
| | | | ||
| | move occurs because `foo` has type `&mut std::option::Option<&i32>`, which does not implement the `Copy` trait | ||
| | move occurs due to use in closure | ||
| move out of `foo` occurs here | ||
| | ||
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0507`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() { | ||
let a = Some("...".to_owned()); | ||
let b = match a { | ||
Some(_) if { drop(a); false } => None, | ||
x => x, //~ ERROR use of moved value: `a` | ||
}; | ||
println!("{:?}", b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0382]: use of moved value: `a` | ||
--> $DIR/issue-31287-drop-in-guard.rs:5:9 | ||
| | ||
LL | let a = Some("...".to_owned()); | ||
| - move occurs because `a` has type `std::option::Option<std::string::String>`, which does not implement the `Copy` trait | ||
LL | let b = match a { | ||
LL | Some(_) if { drop(a); false } => None, | ||
| - value moved here | ||
LL | x => x, | ||
| ^ value used here after move | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |