Skip to content

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

Closed
@lcnr

Description

@lcnr
#![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 }]>() {}
  | ^^^^^^^^^^^^^^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

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