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

cycle error when dealing with an unevaluated const in the type of a const param #74101

Closed
lcnr opened this issue Jul 6, 2020 · 0 comments · Fixed by #74159
Closed

cycle error when dealing with an unevaluated const in the type of a const param #74101

lcnr opened this issue Jul 6, 2020 · 0 comments · Fixed by #74159
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. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@lcnr
Copy link
Contributor

lcnr commented Jul 6, 2020

#![feature(const_generics)]

fn foo<const N: [u8; { 3 + 1 }]>() {}

should compile, but currently results in the following. I am kind of surprised that this ends up with 3 separate cycle errors.

warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error[E0391]: cycle detected when computing type of `foo::N`
 --> src/lib.rs:3:14
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |              ^
  |
  = note: ...which again requires computing type of `foo::N`, completing the cycle
note: cycle used when computing type of `foo`
 --> src/lib.rs:3:1
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  | ^^^^^^^^^^^^^^^^^^^^

error[E0391]: cycle detected when computing type of `foo::N`
 --> src/lib.rs:3:14
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |              ^
  |
note: ...which requires const-evaluating + checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires const-evaluating + checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires const-evaluating `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires optimizing MIR for `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires elaborating drops for `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires borrow-checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires processing `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires const checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires processing MIR for `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires unsafety-checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires building MIR for `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
  = note: ...which again requires computing type of `foo::N`, completing the cycle
note: cycle used when computing type of `foo`
 --> src/lib.rs:3:1
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  | ^^^^^^^^^^^^^^^^^^^^

error[E0391]: cycle detected when computing type of `foo::N`
 --> src/lib.rs:3:14
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |              ^
  |
note: ...which requires const-evaluating + checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires const-evaluating + checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires const-evaluating `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires optimizing MIR for `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires elaborating drops for `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
note: ...which requires borrow-checking `foo::{{constant}}#0`...
 --> src/lib.rs:3:22
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  |                      ^^^^^^^^^
  = note: ...which again requires computing type of `foo::N`, completing the cycle
note: cycle used when computing type of `foo`
 --> src/lib.rs:3:1
  |
3 | fn foo<const N: [u8; { 3 + 1 }]>() {}
  | ^^^^^^^^^^^^^^^^^^^^
@lcnr lcnr added C-bug Category: This is a bug. A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Jul 6, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
forbid generic params in the type of const params

implements and closes rust-lang#74152

fixes rust-lang#74101, closes rust-lang#71169, fixes rust-lang#73491, closes rust-lang#62878

@eddyb and I talked [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203405696) about this and we probably want to also forbid generic consts in the default
type of a parameter, e.g. `struct Foo<T, U = [u8; std::mem::size_of::<T>()]>`, this is currently still allowed
and I will probably fix that in a followup PR.

r? @varkor @eddyb
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
forbid generic params in the type of const params

implements and closes rust-lang#74152

fixes rust-lang#74101, closes rust-lang#71169, fixes rust-lang#73491, closes rust-lang#62878

@eddyb and I talked [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203405696) about this and we probably want to also forbid generic consts in the default
type of a parameter, e.g. `struct Foo<T, U = [u8; std::mem::size_of::<T>()]>`, this is currently still allowed
and I will probably fix that in a followup PR.

r? @varkor @eddyb
@bors bors closed this as completed in 6ef0dfa Jul 16, 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. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant