2018-05-15 16:23:00 -05: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 09:29:35 -06:00
|
|
|
#![feature(if_let_guard)]
|
|
|
|
|
2018-05-15 16:23:00 -05:00
|
|
|
fn main() {
|
|
|
|
match Some(&4) {
|
|
|
|
None => {},
|
|
|
|
ref mut foo
|
|
|
|
if { (|| { let bar = foo; bar.take() })(); false } => {},
|
2019-05-05 06:02:32 -05:00
|
|
|
//~^ ERROR cannot move out of `foo` in pattern guard [E0507]
|
2018-05-15 16:23:00 -05:00
|
|
|
Some(s) => std::process::exit(*s),
|
|
|
|
}
|
2022-12-21 09:29:35 -06: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 16:23:00 -05:00
|
|
|
}
|