-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerfixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.
Description
If you borrow immutably in an if
test, the borrow lasts for the whole if
expression. This means that mutable borrows in the clauses will cause the borrow checker to fail.
This can also happen when borrowing in the match expression, and needing a mutable borrow in one of the arms.
See here for an example where the if borrows boxes, which causes the nearest upwards @mut
to freeze. Then remove_child()
which needs to borrow mutably conflicts.
https://github.com/mozilla/servo/blob/master/src/servo/layout/box_builder.rs#L387-L411
Updated example from @Wyverald
fn main() {
let mut vec = vec!();
match vec.first() {
None => vec.push(5),
Some(v) => unreachable!(),
}
}
jamesmcm and schneiderfelipe
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerfixed-by-NLLBugs fixed, but only when NLL is enabled.Bugs fixed, but only when NLL is enabled.