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

E0433 and E0599 should suggest correct type when it is known #137148

Open
QuineDot opened this issue Feb 16, 2025 · 1 comment
Open

E0433 and E0599 should suggest correct type when it is known #137148

QuineDot opened this issue Feb 16, 2025 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-lack-of-suggestion Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@QuineDot
Copy link

QuineDot commented Feb 16, 2025

Code

pub enum EyeRoll {
    This(String),
    That(bool),
}

fn example(er: EyeRoll) {
    match &er {
        EyeForgor::This(beep) => {}
        EyeForgor::That(boop) => {}
    }
    match &er {
        Result::This(beep) => {}
        Result::That(boop) => {}
    }
}

Current output

error[E0599]: no variant or associated item named `This` found for enum `Result` in the current scope
  --> src/lib.rs:12:17
   |
12 |         Result::This(beep) => {}
   |                 ^^^^ variant or associated item not found in `Result<_, _>`

error[E0599]: no variant or associated item named `That` found for enum `Result` in the current scope
  --> src/lib.rs:13:17
   |
13 |         Result::That(boop) => {}
   |                 ^^^^ variant or associated item not found in `Result<_, _>`

error[E0433]: failed to resolve: use of undeclared type `EyeForgor`
 --> src/lib.rs:8:9
  |
8 |         EyeForgor::This(beep) => {}
  |         ^^^^^^^^^ use of undeclared type `EyeForgor`

error[E0433]: failed to resolve: use of undeclared type `EyeForgor`
 --> src/lib.rs:9:9
  |
9 |         EyeForgor::That(boop) => {}
  |         ^^^^^^^^^ use of undeclared type `EyeForgor`

Desired output

error[E0308]: mismatched types
  --> src/lib.rs:12:17
   |
12 |         Result::This(beep) => {}
   |         ^^^^^^ expected `EyeRoll`, found `Result<_, _>`

error[E0433]: failed to resolve: use of undeclared type `EyeForgor`
 --> src/lib.rs:9:9
  |
9 |         EyeForgor::That(boop) => {}
  |         ^^^^^^^^^ use of undeclared type `EyeForgor`
help: a pattern on the `EyeRoll` type is expected, try:
  |
9 |         EyeRoll::That(boop) => {}
  |         ~~~~~~~

Rationale and extra context

Rust is usually helpful in telling the programmer what they probably meant, but not in this case. I was working in a file far away from an enum import and remembered the variant names but not the enum name. Dummy names made the compiler give up with E0433, and existing-but-incorrect names made it give up with E0599. Diagnostics should have been able to tell what type was expected, and suggested it.

Playground.

Other cases

Rust Version

Playground.

Build using the Stable version: 1.84.1
Build using the Beta version: 1.85.0-beta.9 (2025-02-13 461de7492e5354419cf2)
Build using the Nightly version: 1.86.0-nightly (2025-02-15 9cd60bd2ccc41bc898d2)

Anything else?

No response

@QuineDot QuineDot 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 Feb 16, 2025
@fmease fmease added the D-lack-of-suggestion Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic. label Mar 20, 2025
@xizheyin
Copy link
Contributor

@rustbot claim

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 D-lack-of-suggestion Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic. 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

3 participants