Skip to content

Misplaced span for the error "does not live long enough" #39268

Closed
@KalitaAlexey

Description

@KalitaAlexey

Playground

Code:

fn main() {
    let mut x = &5;
    {
        let y = 5;
        x = &y;
    }
}

Compiler's output:

error: `y` does not live long enough
 --> <anon>:6:5
  |
5 |         x = &y;
  |              - borrow occurs here
6 |     }
  |     ^ `y` dropped here while still borrowed
7 | }
  | - borrowed value needs to live until here

error: aborting due to previous error

Look at --> <anon>:6:5.
It points to the },
but I expected it to point to the y.

Look at | ^y dropped here while still borrowed.
It is treated as a primary span,
but I expected | - borrow occurs here to be treated as a primary span.

It is bad for editors, i.e., VSCode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions