diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/test/ui/const-generics/type-dependent/issue-61936.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/const-generics/type-dependent/issue-61936.rs')
-rw-r--r-- | src/test/ui/const-generics/type-dependent/issue-61936.rs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/test/ui/const-generics/type-dependent/issue-61936.rs b/src/test/ui/const-generics/type-dependent/issue-61936.rs deleted file mode 100644 index 7216b25f0..000000000 --- a/src/test/ui/const-generics/type-dependent/issue-61936.rs +++ /dev/null @@ -1,47 +0,0 @@ -// run-pass - -trait SliceExt<T: Clone> { - fn array_windows_example<'a, const N: usize>(&'a self) -> ArrayWindowsExample<'a, T, N>; -} - -impl <T: Clone> SliceExt<T> for [T] { - fn array_windows_example<'a, const N: usize>(&'a self) -> ArrayWindowsExample<'a, T, N> { - ArrayWindowsExample{ idx: 0, slice: &self } - } -} - -struct ArrayWindowsExample<'a, T, const N: usize> { - slice: &'a [T], - idx: usize, -} - -impl <'a, T: Clone, const N: usize> Iterator for ArrayWindowsExample<'a, T, N> { - type Item = [T; N]; - fn next(&mut self) -> Option<Self::Item> { - // Note: this is unsound for some `T` and not meant as an example - // on how to implement `ArrayWindows`. - 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[self.idx..].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![0; 100]; - - for array in v.as_slice().array_windows_example::<FOUR>() { - assert_eq!(array, [0, 0, 0, 0]) - } -} |