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

Type mismatch errors through generic enums could be clearer #105240

Open
jruderman opened this issue Dec 4, 2022 · 0 comments
Open

Type mismatch errors through generic enums could be clearer #105240

jruderman opened this issue Dec 4, 2022 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

Code

playground

enum A<T> {
    X(T)
}

fn f() -> A<()> {
    A::X(0_u32)
}

fn main() {}

Current output

error[E0308]: mismatched types
 --> src/main.rs:6:10
  |
6 |     A::X(0_u32)
  |     ---- ^^^^^ expected `()`, found `u32`
  |     |
  |     arguments to this enum variant are incorrect
  |
note: tuple variant defined here
 --> src/main.rs:2:5
  |
2 |     X(T)
  |     ^

Due to the use of generics, seeing the definition of the enum variant doesn't really get at the root of the problem.

Ideal output

error[E0308]: mismatched types
 --> src/main.rs:6:10
  |
6 |     A::X(0_u32)
  |     ---- ^^^^^ expected `()`, found `u32`
  |     |
  |     arguments to this enum variant are incorrect

note: expected `()` due to the function signature specifying the generic type for `A`:
  |
5 | fn f() -> A<()> {
  |             ^^

Impact

This can happen with Option or Result, which are common return types.

@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 4, 2022
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant