Closed
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
Area: const generics (parameters and arguments)Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(const_generics)]`Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.