Closed
Description
Hi, I'm trying to learn how to use the new const generics stuff and I ICEd the compiler. Here's the code:
#![feature(const_generics)]
trait SliceExt<T: Clone> {
fn array_windows<'a, const N: usize>(&'a self) -> ArrayWindows<'a, T, {N}>;
}
impl <T: Clone> SliceExt<T> for [T] {
fn array_windows<'a, const N: usize>(&'a self) -> ArrayWindows<'a, T, {N}> {
ArrayWindows{ idx: 0, slice: &self }
}
}
struct ArrayWindows<'a, T, const N: usize> {
slice: &'a [T],
idx: usize,
}
impl <'a, T: Clone, const N: usize> Iterator for ArrayWindows<'a, T, {N}> {
type Item = [T; N];
fn next(&mut self) -> Option<Self::Item> {
let mut res = unsafe{ std::mem::zeroed() };
let mut ptr = &mut res as *mut [T; N] as *mut T;
for i in 0..N {
match self.slice[i..].get(i) {
None => return None,
Some(elem) => unsafe { std::ptr::write_volatile(ptr, elem.clone())},
};
ptr = ptr.wrapping_add(1);
self.idx += 1;
}
Some(res)
}
}
const FOUR: usize = 4;
fn main() {
let v = vec![100; 0usize];
for array in v.as_slice().array_windows::<{FOUR}>() {
// println!("{:?}", array);
}
}
I can't give you the verbose compiler info because this was done on play.rust-lang.org but here's the version:
note: rustc 1.37.0-nightly (b25ee6449 2019-06-17) running on x86_64-unknown-linux-gnu
note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
Metadata
Metadata
Assignees
Labels
Area: Code generationArea: const generics (parameters and arguments)Category: This is a bug.`#![feature(const_generics)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.This issue requires a nightly compiler in some way.