Skip to content

Incorrect error suggestion when using a type that does not recursively derive PartialEq, Eq #76183

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

Closed
CDirkx opened this issue Aug 31, 2020 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CDirkx
Copy link
Contributor

CDirkx commented Aug 31, 2020

The following code

#![feature(const_generics)]
#![feature(structural_match)]

struct Inner;

#[derive(PartialEq, Eq)]
struct Outer {
    inner: Inner
}

struct S<const O: Outer>;
const C : S<{ Outer { inner: Inner } }> = S;

results in the error

error[E0741]: `Outer` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
  --> src/lib.rs:11:19
   |
   | struct S<const O: Outer>;
   |                   ^^^^^ `Outer` doesn't derive both `PartialEq` and `Eq`

Which is not correct: Outer does derive PartialEq and Eq.

The true error is that Inner does not derive the traits (or implements StructuralEq and StructuralPartialEq), however it is probably not a good idea to leak this type in the error message, as it is an implementation detail?

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. labels Aug 31, 2020
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@estebank
Copy link
Contributor

The suggestions now guide you in the right direction:

error[[E0741]](https://doc.rust-lang.org/nightly/error_codes/E0741.html): `Outer` must implement `ConstParamTy` to be used as the type of a const generic parameter
  --> src/lib.rs:12:19
   |
12 | struct S<const O: Outer>;
   |                   ^^^^^
   |
help: add `#[derive(ConstParamTy)]` to the struct
   |
8  + #[derive(ConstParamTy)]
9  | struct Outer {
   |
error[[E0204]](https://doc.rust-lang.org/nightly/error_codes/E0204.html): the trait `ConstParamTy` cannot be implemented for this type
 --> src/lib.rs:7:25
  |
7 | #[derive(PartialEq, Eq, ConstParamTy)]
  |                         ^^^^^^^^^^^^
8 | struct Outer {
9 |     inner: Inner
  |     ------------ this field does not implement `ConstParamTy`
  |
  = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
error[[E0277]](https://doc.rust-lang.org/nightly/error_codes/E0277.html): the type `Inner` does not `#[derive(PartialEq)]`
 --> src/lib.rs:5:10
  |
5 | #[derive(ConstParamTy)]
  |          ^^^^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `Inner`
  |
note: required by a bound in `ConstParamTy`
 --> /rustc/32303b219d4dffa447aa606bc11c7a648f44a862/library/core/src/marker.rs:993:1
  = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)

error[[E0277]](https://doc.rust-lang.org/nightly/error_codes/E0277.html): the type `Inner` does not `#[derive(Eq)]`
 --> src/lib.rs:5:10
  |
5 | #[derive(ConstParamTy)]
  |          ^^^^^^^^^^^^ the trait `StructuralEq` is not implemented for `Inner`
  |
note: required by a bound in `ConstParamTy`
 --> /rustc/32303b219d4dffa447aa606bc11c7a648f44a862/library/core/src/marker.rs:993:1
  = note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)

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 C-bug Category: This is a bug. 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

4 participants