Skip to content

no place to add evaluatable bounds to assoc const items #104400

Closed
@psionic12

Description

@psionic12

Example:

trait Foo {
    const N: usize;
    const ARRAY: [i32;Self::N];
}

The compiler will report an error:

error: unconstrained generic constant
  --> src/main.rs:38:5
   |
38 |     const ARRAY: [i32;Self::N];
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: try adding a `where` bound using this expression: `where [(); Self::N]:`

Honestly speaking, I don't get what the suggestion means. Is it allowed to use generic_const_exprs like this? Or the only way to do this is by writing

trait Foo<const N: usize> {
    const ARRAY: [i32;N];
}

?

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions