Closed
Description
This code fails to compile:
fn foo(_: &mut i32) -> bool { true }
fn main() {
let opt = Some(92);
let mut x = 62;
if let Some(_) = opt {
} else if foo(&mut x) {
}
}
error
error[E0301]: cannot mutably borrow in a pattern guard
--> main.rs:9:19
|
9 | } else if foo(&mut x) {
| ^^^^^^ borrowed mutably in pattern guard
error[E0301]: cannot mutably borrow in a pattern guard
--> main.rs:9:24
|
9 | } else if foo(&mut x) {
| ^ borrowed mutably in pattern guard
error: aborting due to 2 previous errors
I believe this is a bug, because you can just add a pair of braces to "fix" it:
if let Some(_) = opt {
} else { if foo(&mut x) {
} }