Skip to content

Provide context when type error happens due to different fn arguments with the same type parameter are called with different types #116615

Closed

Description

@estebank

Code

fn main() {
    foo(1, 2.);
}
fn foo<T>(a: T, b: T) {}

Current output

error[E0308]: mismatched types
 --> src/main.rs:2:12
  |
2 |     foo(1, 2.);
  |     ---    ^^ expected integer, found floating-point number
  |     |
  |     arguments to this function are incorrect
  |
note: function defined here
 --> src/main.rs:4:4
  |
4 | fn foo<T>(a: T, b: T) {}
  |    ^^^          ----

Desired output

error[E0308]: mismatched types
 --> src/main.rs:2:12
  |
2 |     foo(1, 2.);
  |     --- -  ^^ expected integer, found floating-point number
  |     |   |
  |     |   expected because that argument needs to match the integer type of this parameter
  |     |
  |     arguments to this function are incorrect
  |
note: function defined here
 --> src/main.rs:4:4
  |
4 | fn foo<T>(a: T, b: T) {}
  |    ^^^ -  ----  ----
  |        |  |     |
  |        |  |     this parameter needs to match the type of `a`
  |        |  `b` needs to match the type of this parameter
  |        `a` and `b` both reference type parameter `T`

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 10, 2023
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 10, 2023
  3. added
    D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.
    D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 10, 2023
  4. strottos commented on Feb 21, 2024

    @strottos
    Contributor

    @rustbot claim

    I think I can see how to implement this, will give it a go and unassign if it doesn't work.

  5. strottos commented on Feb 25, 2024

    @strottos
    Contributor

    Spent the last week on this now and put a draft PR here for feedback at this stage, though not essential if I don't get it at this stage: #121595

    It's mostly working now, though there are likely to be improvements yet and I'd like to do a review of it myself before pushing even which I'll probably do later next week.

  6. added a commit that references this issue on Apr 3, 2024
  7. added a commit that references this issue on Apr 3, 2024
  8. strottos commented on Apr 4, 2024

    @strottos
    Contributor

    This has been merged now, I believe the issue can be closed.

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-type-systemArea: Type systemD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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