We currently have a separate mir::BorrowKind for the mutable borrows for closure upvars.
BorrowKind::Unique is an ordinary mutable borrow, requiring its target to be invariant, needing unique access, except that the target is not necessarily required to be marked as mut by the user.
We should merge this into BorrowKind::Mut, resulting in the following setup:
enum BorrowKind {
Shared,
Shallow,
Mut { kind: MutBorrowKind },
}
enum MutBorrowKind {
Default,
TwoPhaseBorrow,
ClosureCapture,
}
It is quite worrying to me that fn BorrowKind::mutability simply returns Mutability::Not for BorrowKind::Unique
|
pub fn mutability(&self) -> Mutability { |
|
match *self { |
|
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => Mutability::Not, |
|
BorrowKind::Mut { .. } => Mutability::Mut, |
|
} |
|
} |
This already caused a bug in #112056 where we used PlaceContext::NonMutatingUse for unique borrows, which resulted in us getting the wrong variance, cc #112070.
We currently have a separate
mir::BorrowKindfor the mutable borrows for closure upvars.BorrowKind::Uniqueis an ordinary mutable borrow, requiring its target to be invariant, needing unique access, except that the target is not necessarily required to be marked asmutby the user.We should merge this into
BorrowKind::Mut, resulting in the following setup:It is quite worrying to me that
fn BorrowKind::mutabilitysimply returnsMutability::NotforBorrowKind::Uniquerust/compiler/rustc_middle/src/mir/mod.rs
Lines 2030 to 2035 in 99ff5af
This already caused a bug in #112056 where we used
PlaceContext::NonMutatingUsefor unique borrows, which resulted in us getting the wrong variance, cc #112070.