-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
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.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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
The code:
#![feature(const_generics)]
use core::ptr::null_mut;
#[derive(Clone, Copy, Debug)]
#[repr(usize)]
pub enum ArrayCount {
Values3 = 3,
Values4 = 4,
Values6 = 6
}
/// Non-Copy type!
#[repr(transparent)]
struct ArrayItem<T>(*mut T);
impl<T> ArrayItem<T> {
pub fn new() -> Self {
Self(null_mut())
}
}
#[repr(transparent)]
pub struct MyArray<T, const COUNT: ArrayCount>([ArrayItem<T>; COUNT as usize]);
impl<T> MyArray<T, {ArrayCount::Values3}> {
pub(crate) const fn new() -> Self {
Self([
ArrayItem::new(),
ArrayItem::new(),
ArrayItem::new(),
])
}
}
fn main() {
}
It produced error:
error[E0308]: mismatched types
--> src/main.rs:28:14
|
28 | Self([
| ______________^
29 | | ArrayItem::new(),
30 | | ArrayItem::new(),
31 | | ArrayItem::new(),
32 | | ])
| |_________^ expected `COUNT as usize`, found `3usize`
|
= note: expected type `[ArrayItem<T>; _]`
found type `[ArrayItem<T>; 3]`
Although Constants in array repeat expressions RFC not yet implemented, this code must work already.
Or I'm wrong and this syntax does not supported by const-generics?
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.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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.