Skip to content

Misleading diagnostic for error[E0277] #139251

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

Open
jjl9807 opened this issue Apr 2, 2025 · 0 comments · May be fixed by #139316
Open

Misleading diagnostic for error[E0277] #139251

jjl9807 opened this issue Apr 2, 2025 · 0 comments · May be fixed by #139316
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jjl9807
Copy link

jjl9807 commented Apr 2, 2025

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

@jjl9807 jjl9807 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 Apr 2, 2025
@fmease fmease added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Apr 4, 2025
@jieyouxu jieyouxu added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label May 1, 2025
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 A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants