2018-05-15 21:23:00 +00:00
|
|
|
// Issue 27282: Example 1: This sidesteps the AST checks disallowing
|
|
|
|
// mutable borrows in match guards by hiding the mutable borrow in a
|
|
|
|
// guard behind a move (of the ref mut pattern id) within a closure.
|
|
|
|
|
2022-12-21 15:29:35 +00:00
|
|
|
#![feature(if_let_guard)]
|
|
|
|
|
2018-05-15 21:23:00 +00:00
|
|
|
fn main() {
|
|
|
|
match Some(&4) {
|
|
|
|
None => {},
|
|
|
|
ref mut foo
|
|
|
|
if { (|| { let bar = foo; bar.take() })(); false } => {},
|
2019-05-05 11:02:32 +00:00
|
|
|
//~^ ERROR cannot move out of `foo` in pattern guard [E0507]
|
2018-05-15 21:23:00 +00:00
|
|
|
Some(s) => std::process::exit(*s),
|
|
|
|
}
|
2022-12-21 15:29:35 +00:00
|
|
|
|
|
|
|
match Some(&4) {
|
|
|
|
None => {},
|
|
|
|
ref mut foo
|
|
|
|
if let Some(()) = { (|| { let bar = foo; bar.take() })(); None } => {},
|
|
|
|
//~^ ERROR cannot move out of `foo` in pattern guard [E0507]
|
|
|
|
Some(s) => std::process::exit(*s),
|
|
|
|
}
|
2018-05-15 21:23:00 +00:00
|
|
|
}
|