Closed
Description
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
rust/compiler/rustc_middle/src/mir/mod.rs
Lines 2030 to 2035 in 99ff5af
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.