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
@estebank

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

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