Skip to content

Diagnostic points to code with no explanation #148392

@theemathas

Description

@theemathas

Code

#![allow(unused)]
fn main() {
    let a = 0;
    let mut b = None;
    move || {
        b = Some(&a);
    };
}

Current output

error[E0521]: borrowed data escapes outside of closure
 --> src/main.rs:6:9
  |
4 |     let mut b = None;
  |         ----- `b` declared here, outside of the closure body
5 |     move || {
6 |         b = Some(&a);
  |         ^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0521`.

Desired output

Rationale and extra context

When the compiler points to a piece of code, it usually explains how that code is relevant. Here, however, the compiler just silently points there for some reason.

Other cases

Rust Version

Reproducible on the playground with version 1.93.0-nightly (2025-11-01 bd3ac0330018c23b111b)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions