E0433 and E0599 should suggest correct type when it is known
Open
@xizheyin is already working on this.
Since Mar 20, 2025.
A-diagnostics
D-lack-of-suggestion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.