Skip to content

Missing suggestion to dereference LHS of assignment when LHS is invalid #93980

Closed
@compiler-errors

Description

@compiler-errors

Given the following code:

fn main() {
    let mut x: Vec<()> = vec![()];
    x.last_mut().unwrap() = ();
}

The current output is:

error[E0070]: invalid left-hand side of assignment
 --> src/main.rs:3:27
  |
3 |     x.last_mut().unwrap() = ();
  |     --------------------- ^
  |     |
  |     cannot assign to this expression

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

Ideally the output should look like:

error[E0070]: invalid left-hand side of assignment
 --> src/main.rs:3:27
  |
3 |     x.last_mut().unwrap() = ();
  |     --------------------- ^
  |     |
  |     cannot assign to this expression

Note: consider dereferencing the left-hand side
3 |     *x.last_mut().unwrap() = ();
        +

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

The root cause seems to be the coersion error being suppressed, since there is already logic that suggest dereferencing the LHS of an assignment operator. In fact, this diagnostic code path is being hit, but somewhere along the way the diagnostic is being canceled (hence the fact that we only see this "invalid left-hand side of assignment" error being emitted and not an error about not being able to relate &mut () and ().)

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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