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