Skip to content

Wrong diagnostic: Type must be annotated #[derive(PartialEq, Eq)] to be used as the type of a const parameter #80471

Open
@vmarkushin

Description

@vmarkushin

I tried this code:

#![feature(const_generics)]

#[derive(PartialEq, Eq)]
enum Nat {
    Z,
    S(Box<Nat>)
}

fn foo<const N: Nat>() {}

And got this error:

error[E0741]: `Nat` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
 --> src/lib.rs:9:17
  |
9 | fn foo<const N: Nat>() {}
  |                 ^^^ `Nat` doesn't derive both `PartialEq` and `Eq`

The code without the const parameter compiles, though:

#![feature(const_generics)]

#[derive(PartialEq, Eq)]
enum Nat {
    Z,
    S(Box<Nat>)
}

// fn foo<const N: Nat>() {}

Meta

rustc +nightly --version --verbose:

rustc 1.50.0-nightly (0edce6f4b 2020-12-24)
binary: rustc
commit-hash: 0edce6f4bbb4514482537f569f0b8ef48e71e0a0
commit-date: 2020-12-24
host: x86_64-apple-darwin
release: 1.50.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions