Skip to content

MIR borrowck: error message confuses locals and temporaries #46471

Closed
@arielb1

Description

@arielb1

e.g.:

fn foo() -> &u32 {
    let x = 0;
    &x
}

Gives the following error:

error[E0597]: `x` does not live long enough (Ast)
 --> foo.rs:4:6
  |
4 |     &x
  |      ^ does not live long enough
5 | }
  | - borrowed value only lives until here
  |
  = note: borrowed value must be valid for the static lifetime...

error[E0597]: borrowed value does not live long enough (Mir)
 --> foo.rs:5:2
  |
3 |     let x = 0;
  |         - temporary value created here
4 |     &x
5 | }
  | -^ temporary value dropped here while still borrowed
  | |
  | temporary value needs to live until here
  |
  = note: consider using a `let` binding to increase its lifetime

error: aborting due to 2 previous errors

The MIR error message should be more like the AST one

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions