Closed
Description
When returning an const length array from an associated function the length is lost and it becomes a [T; _] array.
I tried this code:
(Playground)
#![feature(const_generics)]
struct X;
impl X {
pub fn getn<const N: usize>(&self) -> [u8; N] {
getn::<N>()
}
}
fn getn<const N: usize>() -> [u8; N] {
unsafe {
std::mem::zeroed()
}
}
fn test() {
// works
let [a,b,c] = getn::<3>();
// cannot pattern-match on an array without a fixed length
let [a,b,c] = X.getn::<3>();
// mismatched types, expected array `[u8; 3]` found array `[u8; _]`
let arr: [u8; 3] = X.getn::<3>();
}
I expected to see this happen:
all lines in test compile
Instead, this happened:
functions from the impl did not return a const array
Meta
rustc --version --verbose
:
rustc 1.41.0-nightly (412f43ac5 2019-11-24)
binary: rustc
commit-hash: 412f43ac5b4ae8c3599e71c6972112e9be4758fa
commit-date: 2019-11-24
host: x86_64-unknown-linux-gnu
release: 1.41.0-nightly
LLVM version: 9.0