pub enum FakeBorrowKind {
Shallow,
Deep,
}
Variants§
Shallow
A shared shallow borrow. The immediately borrowed place must be immutable, but projections
from it don’t need to be. For example, a shallow borrow of a.b
doesn’t conflict with a
mutable borrow of a.b.c
.
This is used when lowering matches: when matching on a place we want to ensure that place have the same value from the start of the match until an arm is selected. This prevents this code from compiling:
let mut x = &Some(0);
match *x {
None => (),
Some(_) if { x = &None; false } => (),
Some(_) => (),
}
This can’t be a shared borrow because mutably borrowing (*x as Some).0
should not checking
the discriminant or accessing other variants, because the mutating (*x as Some).0
can’t
affect the discriminant of x
. E.g. the following is allowed:
let mut x = Some(0);
match x {
Some(_)
if {
if let Some(ref mut y) = x {
*y += 1;
};
true
} => {}
_ => {}
}
Deep
A shared (deep) borrow. Data must be immutable and is aliasable.
This is used when lowering deref patterns, where shallow borrows wouldn’t prevent something like: