-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-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
fn main() {
let a: usize;
let b: usize;
(a, b) = (123, &mut 123);
}
Current output
error[E0308]: mismatched types
--> src/main.rs:17:9
|
15 | let b: usize;
| ----- expected due to this type
16 |
17 | (a, b) = (123, &mut 123);
| ^ expected `usize`, found `&mut {integer}`
|
help: consider dereferencing the borrow
|
17 | (a, *b) = (123, &mut 123);
| +
Desired output
error[E0308]: mismatched types
--> src/main.rs:17:9
|
15 | let b: usize;
| ----- expected due to this type
16 |
17 | (a, b) = (123, &mut 123);
| ^ expected `usize`, found `&mut {integer}`
|
help: consider dereferencing the borrow
|
17 | (a, b) = (123, *&mut 123);
| +
Although this cannot be always applied, e.g. consider:
fn main() {
let a: usize;
let b: usize;
(a, b) = foo();
}
fn foo() -> (usize, &'static mut usize) {
todo!()
}
Rationale and extra context
No response
Other cases
No response
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-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.