Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

const generics: error[E0391]: cycle detected when const-evaluating + checking Foo::{{constant}}#0 #67185

Closed
is8ac opened this issue Dec 9, 2019 · 5 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@is8ac
Copy link

is8ac commented Dec 9, 2019

Source

#![feature(const_generics)]

trait Baz {
    type Quaks;
}
impl Baz for u8 {
    type Quaks = [u16; 3];
}

trait Bar {}
impl Bar for [u16; 3] {}
impl Bar for [[u16; 3]; 2] {}

trait Foo
where
    [<u8 as Baz>::Quaks; 2]: Bar,
    <u8 as Baz>::Quaks: Bar,
{
}

fn main() {}

Error

[isaac@d6-arch bitnn]$ rustc src/bin/cycle_demo.rs 
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/bin/cycle_demo.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error[E0391]: cycle detected when const-evaluating + checking `Foo::{{constant}}#0`
  --> src/bin/cycle_demo.rs:17:26
   |
17 |     [<u8 as Baz>::Quaks; 2]: Bar,
   |                          ^
   |
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
  --> src/bin/cycle_demo.rs:17:26
   |
17 |     [<u8 as Baz>::Quaks; 2]: Bar,
   |                          ^
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
  --> src/bin/cycle_demo.rs:17:26
   |
17 |     [<u8 as Baz>::Quaks; 2]: Bar,
   |                          ^
note: ...which requires processing `Foo::{{constant}}#0`...
  --> src/bin/cycle_demo.rs:17:26
   |
17 |     [<u8 as Baz>::Quaks; 2]: Bar,
   |                          ^
note: ...which requires processing `Foo::{{constant}}#0`...
  --> src/bin/cycle_demo.rs:17:26
   |
17 |     [<u8 as Baz>::Quaks; 2]: Bar,
   |                          ^
   = note: ...which again requires const-evaluating + checking `Foo::{{constant}}#0`, completing the cycle
note: cycle used when processing `Foo`
  --> src/bin/cycle_demo.rs:14:1
   |
14 | / trait Foo
15 | | where
16 | |     Self: Sized,
17 | |     [<u8 as Baz>::Quaks; 2]: Bar,
18 | |     <u8 as Baz>::Quaks: Bar,
19 | | {
20 | | }
   | |_^

error: aborting due to previous error

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

Remove the line [<u8 as Baz>::Quaks; 2]: Bar, and it compiles.
Removing #![feature(const_generics)] also makes it compile.

Meta

[isaac@d6-arch bitnn]$ rustc --version --verbose
rustc 1.41.0-nightly (59947fcae 2019-12-08)
binary: rustc
commit-hash: 59947fcae6a40df12e33af8c8c7291014b7603e0
commit-date: 2019-12-08
host: x86_64-unknown-linux-gnu
release: 1.41.0-nightly
LLVM version: 9.0
@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)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 9, 2019
@is8ac
Copy link
Author

is8ac commented Dec 10, 2019

The example compiles fine with
rustc 1.41.0-nightly (412f43ac5 2019-11-24), but fails with
rustc 1.41.0-nightly (6d77e45f0 2019-12-04).

@jonas-schievink
Copy link
Contributor

Caused by #66883, but sounds like expected fallout. cc @eddyb

@eddyb
Copy link
Member

eddyb commented Dec 12, 2019

We probably need a way to aggregate these issues and avoid having dozens of duplicates, heh.

Making this work is blocked on lazy normalization.
You can disable const generics, or make your array impls const-generic, there's not really anything else we can properly support atm.

@varkor @yodaldevoid @oli-obk Maybe we should disable generics in scope for plain literals? It's inconsistent but it'd be behind the const_generics feature-gate anyway.

@varkor
Copy link
Member

varkor commented Dec 12, 2019

Maybe we should disable generics in scope for plain literals? It's inconsistent but it'd be behind the const_generics feature-gate anyway.

I had been meaning to do something like this a while ago: I agree there's not much point allowing users to write this if it just doesn't work at all.

@varkor varkor added the A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) label Apr 8, 2020
@lcnr lcnr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jun 9, 2020
@lcnr
Copy link
Contributor

lcnr commented Jun 30, 2020

It seems like we already added tests for this issue in #71973 😅

@lcnr lcnr closed this as completed Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants