Skip to content

NLL diagnostics for ref mut z @ &mut Some(ref a) uses _ as binding name #67565

Closed
@Centril

Description

@Centril

Context: #66296 (comment)

The _ below should be z instead.

error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
  --> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:31
   |
LL |         ref mut z @ &mut Some(ref a) => {
   |         ----------------------^^^^^-
   |         |                     |
   |         |                     immutable borrow occurs here
   |         mutable borrow occurs here
...
LL |             **z = None;
   |             ---------- mutable borrow later used here

cc @mark-i-m @pnkfelix @matthewjasper

cc #65490


Minimal reproducer:

#![feature(bindings_after_at)]

fn foo() {
    let ref mut _z @ ref _a = &mut 1;
    **_z = 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.F-bindings_after_at`#![feature(bindings_after_at)]`NLL-diagnosticsWorking towards the "diagnostic parity" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions