Closed
Description
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());
}
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.