Skip to content

Unexpected error in const generics: constant expression depends on a generic parameter #68630

Closed
@qwerty19106

Description

@qwerty19106

The code:

#![feature(const_generics)]

struct Stack<const N: usize> {
    stack: [u64; {N / 8}],
}

must be compiled but gives error:

error: constant expression depends on a generic parameter
 --> src/lib.rs:4:5
  |
4 |     stack: [u64; {N / 8}],
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = note: this may fail depending on what value the parameter takes

note: rustc 1.42.0-nightly (8a79d08fa 2020-01-27) running on x86_64-unknown-linux-gnu

playground

It is the same as #61368, but not ICE.

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)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.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