-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Const generics: Incorrect error "wrong number of const arguments" with struct constructor #61346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
A-const-generics
Area: const generics (parameters and arguments)
A-inference
Area: Type inference
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
Reduced: #![feature(const_generics)]
pub struct Array<T, const N: usize> {
data: [T; {N}]
}
fn main() {
let _ = Array { data: [0u32; 8] };
} |
I wonder whether the right fix is removing: let infer_consts = position != GenericArgPosition::Type && arg_counts.consts == 0; and just using
which might be "more correct", but is an ICE. However, making this change does fix #60724. |
Interestingly, the following works. #![feature(const_generics)]
pub struct Array<T, const N: usize>([T; N]);
fn main() {
let _ = Array([0u32; 8]);
} So it's not a problem with tuple structs. |
Additionally, this works. #![feature(const_generics)]
pub struct Array<T, const N: usize> { x: [T; N] }
fn main() {
let _ = Array::<u32, 8> { x: [0u32; 8] };
} So there's a problem with the inference. |
Centril
added a commit
to Centril/rust
that referenced
this issue
Jun 10, 2019
Fix issues with const argument inference Fixes rust-lang#60724. Fixes rust-lang#61346. r? @eddyb
Centril
added a commit
to Centril/rust
that referenced
this issue
Jun 10, 2019
Fix issues with const argument inference Fixes rust-lang#60724. Fixes rust-lang#61346. r? @eddyb
Centril
added a commit
to Centril/rust
that referenced
this issue
Jun 10, 2019
Fix issues with const argument inference Fixes rust-lang#60724. Fixes rust-lang#61346. r? @eddyb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-const-generics
Area: const generics (parameters and arguments)
A-inference
Area: Type inference
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
this works fine:
but this fails to compile:
here is the error:
The text was updated successfully, but these errors were encountered: