-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Description
If there already is an issue for this, I apologize. I couldn't find one, but searching for this is a bit hard.
Right now, the borrow checker does not allow a borrow of a variable in the else branch if the let binding borrows the variable.
Example:
let mut m = HashMap::<i64, bool>::new();
if let Some(x) = m.get(&10) {
// do something...
}
else {
m.insert(10, true);
}The m.insert is invalid, because the borrow checker assumes an active borrow for the hashmap.
The Some(x) binding is not in scope anymore, though, and there's no way to access x, so this should be allowed.
Metadata
Metadata
Assignees
Labels
No labels