Skip to content

merge BorrowKind::Unique into BorrowKind::Mut #112072

Closed
@lcnr

Description

@lcnr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions