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

On type mismatch involving fn call, point at fn definition #61066

Open
estebank opened this issue May 23, 2019 · 1 comment
Open

On type mismatch involving fn call, point at fn definition #61066

estebank opened this issue May 23, 2019 · 1 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given

fn foo() -> u32 {
    1
}

fn bar() {
    let x: usize = foo();
}

we now present:

error[E0308]: mismatched types
 --> src/lib.rs:6:20
  |
6 |     let x: usize = foo();
  |                    ^^^^^ expected usize, found u32
help: you can convert an `u32` to `usize` and panic if the converted value wouldn't fit
  |
6 |     let x: usize = foo().try_into().unwrap();
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^

We should ideally also point at foo and maybe tell the user to consider changing it.

@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
@lolbinarycat
Copy link
Contributor

this is especially odd considering we do point at the function when the problem is in the argument type:

fn foo(_x: u16) -> usize {
    1
}

fn bar() {
    let x: usize = foo(1_u8);
}

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. 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