-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.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.
Description
this works fine:
#![feature(const_generics)]
pub struct Array<T, const N: usize> ([T; {N}]);
impl <T, const N: usize> Array<T, {N}> {
#[inline]
pub fn cap(&self) -> usize {
{N}
}
}
fn main() {
let arr = Array([0u32; 8]);
println!("{}", arr.cap());
}
but this fails to compile:
#![feature(const_generics)]
pub struct Array<T, const N: usize> {
data: [T; {N}]
}
impl <T, const N: usize> Array<T, {N}> {
#[inline]
pub fn cap(&self) -> usize {
{N}
}
}
fn main() {
let arr = Array { data: [0u32; 8] };
println!("{}", arr.cap());
}
here is the error:
error[E0107]: wrong number of const arguments: expected 1, found 0
--> src/main.rs:28:15
|
28 | let arr = Array { data: [0u32; 8] };
| ^^^^^ expected 1 const argument
error: aborting due to previous error
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.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.