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

Point at cause of expectation for type mismatch on let assignments with explicit type #61067

Closed
estebank opened this issue May 23, 2019 · 0 comments · Fixed by #66539
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given

fn foo() -> i32 {
    let s: i32 = 3usize;
    s
}

we present

error[E0308]: mismatched types
 --> src/lib.rs:2:18
  |
2 |     let s: i32 = 3usize;
  |                  ^^^^^^ expected i32, found usize
help: change the type of the numeric literal from `usize` to `i32`
  |
2 |     let s: i32 = 3i32;
  |                  ^^^^

We would ideally also point at the assignment's type in the same way we do for type mismatches against a return type:

error[E0308]: mismatched types
 --> src/lib.rs:2:18
  |
2 |     let s: i32 = 3usize;
  |            ---   ^^^^^^ expected i32, found usize
  |            |
  |            expected due to this
help: change the type of the numeric literal from `usize` to `i32`
  |
2 |     let s: i32 = 3i32;
  |                  ^^^^
@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels May 23, 2019
@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels May 23, 2019
@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 5, 2019
Centril added a commit to Centril/rust that referenced this issue Nov 20, 2019
Point at type in `let` assignment on type errors

Fix rust-lang#61067.
Centril added a commit to Centril/rust that referenced this issue Nov 21, 2019
Point at type in `let` assignment on type errors

Fix rust-lang#61067.
@bors bors closed this as completed in 62a7839 Nov 24, 2019
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. 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.

2 participants