Skip to content

MIR borrowck: AST error message refers to kind of item that can't be borrowed #46629

Closed
@arielb1

Description

@arielb1

e.g. in E0596:

fn main() {
    let x = 1;
    let y = &mut x; //[ast]~ ERROR [E0596]
                    //[mir]~^ ERROR [E0596]
}

AST borrowck knows that x is an "immutable local variable", but MIR semi-inaccurately calls it an immutable item:

error[E0596]: cannot borrow immutable local variable `x` as mutable (Ast)
  --> /home/ariel/Rust/rust-master/src/test/compile-fail/E0596.rs:16:18
   |
15 |     let x = 1;
   |         - consider changing this to `mut x`
16 |     let y = &mut x; //[ast]~ ERROR [E0596]
   |                  ^ cannot borrow mutably

error[E0596]: cannot borrow immutable item `x` as mutable (Mir)
  --> /home/ariel/Rust/rust-master/src/test/compile-fail/E0596.rs:16:13
   |
16 |     let y = &mut x; //[ast]~ ERROR [E0596]
   |             ^^^^^^ cannot borrow as mutable

error: aborting due to 2 previous errors

The AST code for doing that is actually in mem_categorization, and should be ported to MIR borrowck:

pub fn descriptive_string(&self, tcx: TyCtxt) -> String {

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.NLL-diagnosticsWorking towards the "diagnostic parity" goal

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions