Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler suggests dereferencing LHS of tuple-assign #109991

Closed
Patryk27 opened this issue Apr 6, 2023 · 0 comments · Fixed by #112476
Closed

Compiler suggests dereferencing LHS of tuple-assign #109991

Patryk27 opened this issue Apr 6, 2023 · 0 comments · Fixed by #112476
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Patryk27
Copy link
Contributor

Patryk27 commented Apr 6, 2023

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

@Patryk27 Patryk27 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 6, 2023
@chenyukang chenyukang self-assigned this Apr 7, 2023
@workingjubilee workingjubilee added the D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. label Apr 7, 2023
@bors bors closed this as completed in 3c5d71a Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants