Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

ices/61936.rs: fixed with no errors #425

Merged
merged 1 commit into from
Jul 16, 2020
Merged

Conversation

github-actions[bot]
Copy link
Contributor

Issue: rust-lang/rust#61936

#![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<usize> = vec![100; 0usize];
    
    for array in v.as_slice().array_windows::<{FOUR}>() {
       // println!("{:?}", array);
    }
}
=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/61936.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

warning: unused variable: `array`
  --> /home/runner/work/glacier/glacier/ices/61936.rs:42:9
   |
42 |     for array in v.as_slice().array_windows::<{FOUR}>() {
   |         ^^^^^ help: if this is intentional, prefix it with an underscore: `_array`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 2 warnings emitted

==============

=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /home/runner/work/glacier/glacier/ices/61936.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <rust-lang/rust#44580> for more information

warning: unused variable: `array`
  --> /home/runner/work/glacier/glacier/ices/61936.rs:42:9
   |
42 |     for array in v.as_slice().array_windows::<{FOUR}>() {
   |         ^^^^^ help: if this is intentional, prefix it with an underscore: `_array`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 2 warnings emitted

==============
@Alexendoo Alexendoo merged commit 295a393 into master Jul 16, 2020
@Alexendoo Alexendoo deleted the autofix/ices/61936.rs branch July 16, 2020 12:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants