Skip to content

MIR borrowck: diagnostic for moves out of patterns should be improved #45699

Closed
@arielb1

Description

@arielb1

When a match expression or let statement is used on an lvalue with no ability to move things out, AST borrowck displays a single unified error message while MIR borrowck displays an error message for each binding:

#![feature(box_syntax)]

enum Foo {
    Foo1(Box<u32>, Box<u32>),
    Foo2(Box<u32>),
    Foo3,
}

fn blah() {
    let f = &Foo::Foo1(box 1, box 2);
    match *f {             //~ ERROR cannot move out of
                           //~| cannot move out
        Foo::Foo1(_num1,         //~ NOTE to prevent move
                  _num2) => (),  //~ NOTE and here
        Foo::Foo2(_num) => (),   //~ NOTE and here
        Foo::Foo3 => ()
    }
}

fn main() {}

Displays the following errors:

error[E0507]: cannot move out of borrowed content (Ast)
  --> x.rs:11:11
   |
11 |     match *f {             //~ ERROR cannot move out of
   |           ^^ cannot move out of borrowed content
12 |                            //~| cannot move out
13 |         Foo::Foo1(_num1,         //~ NOTE to prevent move
   |                   ----- hint: to prevent move, use `ref _num1` or `ref mut _num1`
14 |                   _num2) => (),  //~ NOTE and here
   |                   ----- ...and here (use `ref _num2` or `ref mut _num2`)
15 |         Foo::Foo2(_num) => (),   //~ NOTE and here
   |                   ---- ...and here (use `ref _num` or `ref mut _num`)

error[E0507]: cannot move out of borrowed_content (Mir)
  --> x.rs:13:19
   |
13 |         Foo::Foo1(_num1,         //~ NOTE to prevent move
   |                   ^^^^^ cannot move out of borrowed_content

error[E0507]: cannot move out of borrowed_content (Mir)
  --> x.rs:14:19
   |
14 |                   _num2) => (),  //~ NOTE and here
   |                   ^^^^^ cannot move out of borrowed_content

error[E0507]: cannot move out of borrowed_content (Mir)
  --> x.rs:15:19
   |
15 |         Foo::Foo2(_num) => (),   //~ NOTE and here
   |                   ^^^^ cannot move out of borrowed_content

error: aborting due to 4 previous errors

I think this is fairly low priority, but we do want error parity.

Metadata

Metadata

Assignees

Labels

A-borrow-checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.NLL-diagnosticsWorking towards the "diagnostic parity" goalT-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