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 errors #320

Closed
wants to merge 1 commit into from

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![100; 0usize];
    
    for array in v.as_slice().array_windows::<{FOUR}>() {
       // println!("{:?}", array);
    }
}
=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> /home/runner/work/glacier/glacier/ices/61936.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error[E0282]: type annotations needed for `std::vec::Vec<{integer}>`
  --> /home/runner/work/glacier/glacier/ices/61936.rs:40:13
   |
40 |     let v = vec![100; 0usize];
   |         -   ^^^^^^^^^^^^^^^^^ cannot infer type for struct `std::vec::Vec<{integer}>`
   |         |
   |         consider giving `v` a type
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
==============

=== stdout ===
=== stderr ===
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> /home/runner/work/glacier/glacier/ices/61936.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error[E0282]: type annotations needed for `std::vec::Vec<{integer}>`
  --> /home/runner/work/glacier/glacier/ices/61936.rs:40:13
   |
40 |     let v = vec![100; 0usize];
   |         -   ^^^^^^^^^^^^^^^^^ cannot infer type for struct `std::vec::Vec<{integer}>`
   |         |
   |         consider giving `v` a type
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
==============
@Alexendoo Alexendoo closed this Mar 25, 2020
@Alexendoo Alexendoo deleted the autofix/ices/61936.rs branch March 25, 2020 21:11
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