Skip to content

Cycle detected when deriving PartialEq, Eq for type with non-primitive const param. #74950

Closed
@CDirkx

Description

@CDirkx

The following code used to compile on nightly:

#![feature(const_generics)]

#[derive(PartialEq, Eq)]
struct Inner;

#[derive(PartialEq, Eq)]
struct Outer<const I: Inner>;

but now results in

error[E0391]: cycle detected when computing type of `Outer::I`
   --> src\lib.rs:7:20
    |
7   | struct Outer<const I: Inner>;
    |                    ^
    |
    = note: ...which requires computing whether `Inner` implements `PartialStructuralEq` and `StructuralEq`...
    = note: ...which requires evaluating trait selection obligation `Inner: std::marker::StructuralPartialEq`...
note: ...which requires trait impls of `std::marker::StructuralPartialEq`...
   --> .../src/rust\library\core\src\marker.rs:152:1
    |
152 | pub trait StructuralPartialEq {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing type of `<impl at src\lib.rs:6:10: 6:19>`...
   --> src\lib.rs:6:10
    |
6   | #[derive(PartialEq, Eq)]
    |          ^^^^^^^^^
    = note: ...which again requires computing type of `Outer::I`, completing the cycle
note: cycle used when computing type of `<impl at src\lib.rs:6:21: 6:23>`
   --> src\lib.rs:6:21
    |
6   | #[derive(PartialEq, Eq)]
    |                     ^^
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

The same is true for any non-primitive const param, i.e.:

#[derive(PartialEq, Eq)]
struct Outer<const I: Option<usize>>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`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