-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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.
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.