Skip to content

Commit

Permalink
Add tests for rust-lang#27282, rust-lang#31287 as hard errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jul 28, 2019
1 parent 194282b commit b95b8cc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/ui/borrowck/issue-27282-mutation-in-guard.rs
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."),
}
}
15 changes: 15 additions & 0 deletions src/test/ui/borrowck/issue-27282-mutation-in-guard.stderr
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`.
8 changes: 8 additions & 0 deletions src/test/ui/borrowck/issue-31287-drop-in-guard.rs
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);
}
14 changes: 14 additions & 0 deletions src/test/ui/borrowck/issue-31287-drop-in-guard.stderr
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`.

0 comments on commit b95b8cc

Please sign in to comment.