Skip to content

Diagnostic for const generic enum on stable suggests requirements for nightly-only feature (PartialEq, Eq) #95150

Closed
@joshtriplett

Description

@joshtriplett

Given the following code (playground link):

enum E {
    V1,
    V2,
}

struct S<const X: E>;

Rust gives a diagnostic suggesting deriving PartialEq, Eq:

error: `E` is forbidden as the type of a const generic parameter
 --> src/lib.rs:6:19
  |
6 | struct S<const X: E>;
  |                   ^
  |
  = note: the only supported types are integers, `bool` and `char`

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

For more information about this error, try `rustc --explain E0741`.

However, adding #[derive(PartialEq, Eq)] leads the compiler to still give an error about not supporting this.

A non-nightly compiler should not give the second error at all; it should only give the first, saying that the only supported types are integers, bool and char.

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions