Skip to content

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

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
CDirkx opened this issue Jul 30, 2020 · 0 comments · Fixed by #75069
Closed

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

CDirkx opened this issue Jul 30, 2020 · 0 comments · Fixed by #75069
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CDirkx
Copy link
Contributor

CDirkx commented Jul 30, 2020

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>>;
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 30, 2020
tmandry added a commit to tmandry/rust that referenced this issue Aug 19, 2020
move const param structural match checks to wfcheck

fixes rust-lang#75047 fixes rust-lang#74950

We currently check for structural match violations inside of `type_of`.
As we need to check the array length when checking if `[NonEq; arr_len]` is structural match, we potentially require the variance of an expression. Computing the variance requires `type_of` for all types though, resulting in a cycle error.

r? @varkor @eddyb
@bors bors closed this as completed in 672d009 Aug 19, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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.

2 participants