Skip to content

Cannot use generic const argument without {}, despite no conflict #68257

Closed
@DrGabble

Description

@DrGabble

I would expect this code to compile, but it does not:

#![feature(const_generics)]

struct Foo<const A: usize, const B: usize> {
    a: [usize; A],
    b: [usize; B],
}

impl<const A: usize> Foo<A, 1> {
    fn get_b(&self) -> usize {
        self.b[0]
    }
}

impl<const B: usize> Foo<1, B> {
    fn get_a(&self) -> usize {
        self.a[0]
    }
}


fn main() {
    let foo = Foo { a: [0, 3], b: [0] };
    dbg!(foo.get_b());
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: type arguments must be declared prior to const arguments
  --> src/main.rs:14:29
   |
14 | impl<const B: usize> Foo<1, B> {
   |                             ^

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

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