-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
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) {
} }
Metadata
Metadata
Assignees
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.