Skip to content

Const generics: Incorrect error "wrong number of const arguments" with struct constructor #61346

@andreytkachenko

Description

@andreytkachenko

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)A-inferenceArea: Type inferenceC-bugCategory: This is a bug.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