Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
joshtriplett opened this issue Mar 20, 2022 · 4 comments · Fixed by #95820
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@joshtriplett
Copy link
Member

joshtriplett commented Mar 20, 2022

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.

@joshtriplett joshtriplett 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 Mar 20, 2022
@lcnr lcnr added the A-const-generics Area: const generics (parameters and arguments) label Mar 22, 2022
@lcnr
Copy link
Contributor

lcnr commented Mar 22, 2022

assigning this to project-const-generics, getting worked on in https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/error.20msg.20referencing.20stable

@in42
Copy link
Contributor

in42 commented Mar 24, 2022

@rustbot claim

@lcnr lcnr unassigned in42 Apr 7, 2022
@lcnr lcnr added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Apr 7, 2022
@lcnr
Copy link
Contributor

lcnr commented Apr 7, 2022

To fix this issue, you can do the following steps:

  • grep for "forbidden as the type of a const generic parameter"
  • look at that function for a bit
  • change it so that the second error isn't emitted on stable (probably actually change the control flow to start by branching on tcx.features().adt_const_params

In case you are interested but need more help to fix this, feel free to reach out to me on zulip

@OliverMD
Copy link
Contributor

OliverMD commented Apr 7, 2022

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. 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.

4 participants