Misleading diagnostic for `error[E0277]`
Open
Nobody has claimed this yet.
A-diagnostics
A-macros
D-invalid-suggestion
E-needs-bisection
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
enum Foo<T> {
Bar {
v23: T,
y: isize
}
}
fn f(x: &Foo) {
match *x {
Foo::Bar { y: y, v23: x } => {
assert_eq!(x, 1);
assert_eq!(y, 2);
}
}
}
pub fn main() {
let x = Foo::Bar { x: 1, y: 2 };
f(&x);
}
Current output
error[E0107]: missing generics for enum `Foo`
--> test.rs:11:10
|
11 | fn f(x: &Foo) {
| ^^^ expected 1 generic argument
|
note: enum defined here, with 1 generic parameter: `T`
--> test.rs:4:6
|
4 | enum Foo<T> {
| ^^^ -
help: add missing generic argument
|
11 | fn f(x: &Foo<T>) {
| +++
error[E0277]: can't compare `&isize` with `{integer}`
--> test.rs:15:13
|
15 | assert_eq!(y, 2);
| ^^^^^^^^^^^^^^^^ no implementation for `&isize == {integer}`
|
= help: the trait `PartialEq<{integer}>` is not implemented for `&isize`
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider dereferencing here
--> /home/jl-jiang/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs:46:22
|
46 | if !(**left_val == *right_val) {
| +
error[E0559]: variant `Foo<_>::Bar` has no field named `x`
--> test.rs:21:24
|
21 | let x = Foo::Bar { x: 1, y: 2 };
| ^ `Foo<_>::Bar` does not have this field
|
= note: available fields are: `v23`
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0107, E0277, E0559.
For more information about an error, try `rustc --explain E0107`.
Desired output
Rationale and extra context
I'm not entirely sure what the compiler's output should be, but it is inappropriate to suggest modifying the standard library when the issue lies in the user code. This suggestion is clearly flawed.
Other cases
Rust Version
rustc 1.88.0-nightly (e2014e876 2025-04-01)
binary: rustc
commit-hash: e2014e876e3efaa69bf51c19579adb16c3df5f81
commit-date: 2025-04-01
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.1
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.
Research direction
Reproduce the diagnostic using the Rust code and nightly version shown in the issue. Trace the E0277 suggestion that points into the standard library macro and determine how to prevent this inappropriate recommendation; done means the diagnostic no longer suggests modifying unrelated standard-library code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100