Skip to content

struct in type of const param causes ICE #74199

Closed
@lcnr

Description

@lcnr
// check-pass
#![feature(const_generics)]

struct Foo<const N: [u8; {
    struct Foo<const N: usize>;

    impl<const N: usize> Foo<N> {
        fn value() -> usize {
            N
        }
    }

    Foo::<17>::value()
}]>;

fn main() {}

causes an ICE with

warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:2:12
  |
2 | #![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/main.rs:4:18
  |
4 | struct Foo<const N: [u8; {
  |                  ^
  |
  = note: ...which again requires computing type of `Foo::N`, completing the cycle
note: cycle used when computing type of `Foo`
 --> src/main.rs:4:1
  |
4 | struct Foo<const N: [u8; {
  | ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0391]: cycle detected when computing type of `Foo`
  --> src/main.rs:4:1
   |
4  | struct Foo<const N: [u8; {
   | ^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires computing type of `Foo::N`...
  --> src/main.rs:4:18
   |
4  | struct Foo<const N: [u8; {
   |                  ^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
  --> src/main.rs:4:26
   |
4  |   struct Foo<const N: [u8; {
   |  __________________________^
5  | |     struct Foo<const N: usize>;
6  | |
7  | |     impl<const N: usize> Foo<N> {
...  |
13 | |     Foo::<17>::value()
14 | | }]>;
   | |_^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
  --> src/main.rs:4:26
   |
4  |   struct Foo<const N: [u8; {
   |  __________________________^
5  | |     struct Foo<const N: usize>;
6  | |
7  | |     impl<const N: usize> Foo<N> {
...  |
13 | |     Foo::<17>::value()
14 | | }]>;
   | |_^
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
  --> src/main.rs:4:26
   |
4  |   struct Foo<const N: [u8; {
   |  __________________________^
5  | |     struct Foo<const N: usize>;
6  | |
7  | |     impl<const N: usize> Foo<N> {
...  |
13 | |     Foo::<17>::value()
14 | | }]>;
   | |_^
note: ...which requires type-checking `Foo::{{constant}}#0`...
  --> src/main.rs:4:26
   |
4  |   struct Foo<const N: [u8; {
   |  __________________________^
5  | |     struct Foo<const N: usize>;
6  | |
7  | |     impl<const N: usize> Foo<N> {
...  |
13 | |     Foo::<17>::value()
14 | | }]>;
   | |_^
note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`...
  --> src/main.rs:5:5
   |
5  |     struct Foo<const N: usize>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which requires computing the variances for items in this crate...
   = note: ...which again requires computing type of `Foo`, completing the cycle
note: cycle used when collecting item types in top-level module
  --> src/main.rs:2:1
   |
2  | / #![feature(const_generics)]
3  | |
4  | | struct Foo<const N: [u8; {
5  | |     struct Foo<const N: usize>;
...  |
15 | |
16 | | fn main() {}
   | |____________^

error: internal compiler error: src/librustc_typeck/variance/constraints.rs:165:17: `build_constraints_for_item` unsupported for this item
  --> src/main.rs:4:1
   |
4  | / struct Foo<const N: [u8; {
5  | |     struct Foo<const N: usize>;
6  | |
7  | |     impl<const N: usize> Foo<N> {
...  |
13 | |     Foo::<17>::value()
14 | | }]>;
   | |____^

thread 'rustc' panicked at 'Box<Any>', /rustc/8aa18cbdc5d4bc33bd61e2d9a4b643d87f5d21de/src/libstd/macros.rs:13:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.46.0-nightly (8aa18cbdc 2020-07-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: aborting due to 3 previous errors; 1 warning emitted

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)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions