Skip to content

Commit 0201cb8

Browse files
committed
Add tests for #27282, #31287 as hard errors.
1 parent a421e51 commit 0201cb8

4 files changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() {
2+
match Some(&4) {
3+
None => {},
4+
ref mut foo
5+
if {
6+
(|| { let bar = foo; bar.take() })();
7+
//~^ ERROR cannot move out of `foo` in pattern guard
8+
false
9+
} => {},
10+
Some(ref _s) => println!("Note this arm is bogus; the `Some` became `None` in the guard."),
11+
_ => println!("Here is some supposedly unreachable code."),
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0507]: cannot move out of `foo` in pattern guard
2+
--> $DIR/issue-27282-mutation-in-guard.rs:6:18
3+
|
4+
LL | (|| { let bar = foo; bar.take() })();
5+
| ^^ ---
6+
| | |
7+
| | move occurs because `foo` has type `&mut std::option::Option<&i32>`, which does not implement the `Copy` trait
8+
| | move occurs due to use in closure
9+
| move out of `foo` occurs here
10+
|
11+
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0507`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let a = Some("...".to_owned());
3+
let b = match a {
4+
Some(_) if { drop(a); false } => None,
5+
x => x, //~ ERROR use of moved value: `a`
6+
};
7+
println!("{:?}", b);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0382]: use of moved value: `a`
2+
--> $DIR/issue-31287-drop-in-guard.rs:5:9
3+
|
4+
LL | let a = Some("...".to_owned());
5+
| - move occurs because `a` has type `std::option::Option<std::string::String>`, which does not implement the `Copy` trait
6+
LL | let b = match a {
7+
LL | Some(_) if { drop(a); false } => None,
8+
| - value moved here
9+
LL | x => x,
10+
| ^ value used here after move
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)