Skip to content

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

Description

@estebank

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions