- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
let a = &mut 0;
let b = 1;
let r = &b;
let z = a < b;
println!("{r}");Current output
error[E0308]: mismatched types
 --> src/main.rs:5:13
  |
5 | let z = a < b;
  |             ^ expected `&mut _`, found integer
  |
  = note: expected mutable reference `&mut _`
                          found type `{integer}`
help: consider mutably borrowing here
  |
5 | let z = a < &mut b;
  |             ++++
For more information about this error, try `rustc --explain E0308`.Desired output
something along the lines of:
let z = a < b;
        ^ expected `integer`, found &mut _
help: consider dereferencing here
  |
5 | let z = *a < b;
  |         +
For more information about this error, try `rustc --explain E0308`.Rationale and extra context
rustc should not hint to mutably borrow an immutable variable b (or also tell to make it mutable, but this does not work if b is borrowed), it should hint to dereference a (*a < b) or convert a to an immutable reference and reference b (&*a < &b)
Other cases
No response
Anything else?
the same message with stable, beta and nightly, only stable doesnt show where to insert &mut
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.