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

Commit 42adf99

Browse files
authored
Merge pull request #160 from JohnTitor/add-10-ices
Add 10 ICEs
2 parents 229b9fb + 9fedbf6 commit 42adf99

File tree

10 files changed

+205
-0
lines changed

10 files changed

+205
-0
lines changed

ices/61455.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(const_generics)]
2+
3+
use std::mem::transmute;
4+
5+
struct Bug<const N: fn(usize)>;
6+
7+
fn main() {
8+
let x = Bug::<{
9+
unsafe { transmute(|x: u8| {}) }
10+
11+
}>;
12+
}

ices/61747.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(const_generics)]
2+
3+
struct Const<const N: usize>;
4+
5+
impl<const C: usize> Const<{C}> {
6+
fn successor() -> Const<{C + 1}> {
7+
Const
8+
}
9+
}
10+
11+
fn main() {
12+
Const::<1>::successor();
13+
}

ices/61774.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let _: [_; unsafe { std::mem::transmute(|| {}) }];
3+
}

ices/61936.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![feature(const_generics)]
2+
3+
trait SliceExt<T: Clone> {
4+
fn array_windows<'a, const N: usize>(&'a self) -> ArrayWindows<'a, T, {N}>;
5+
}
6+
7+
impl <T: Clone> SliceExt<T> for [T] {
8+
fn array_windows<'a, const N: usize>(&'a self) -> ArrayWindows<'a, T, {N}> {
9+
ArrayWindows{ idx: 0, slice: &self }
10+
}
11+
}
12+
13+
struct ArrayWindows<'a, T, const N: usize> {
14+
slice: &'a [T],
15+
idx: usize,
16+
}
17+
18+
impl <'a, T: Clone, const N: usize> Iterator for ArrayWindows<'a, T, {N}> {
19+
type Item = [T; N];
20+
fn next(&mut self) -> Option<Self::Item> {
21+
let mut res = unsafe{ std::mem::zeroed() };
22+
let mut ptr = &mut res as *mut [T; N] as *mut T;
23+
24+
for i in 0..N {
25+
match self.slice[i..].get(i) {
26+
None => return None,
27+
Some(elem) => unsafe { std::ptr::write_volatile(ptr, elem.clone())},
28+
};
29+
ptr = ptr.wrapping_add(1);
30+
self.idx += 1;
31+
}
32+
33+
Some(res)
34+
}
35+
}
36+
37+
const FOUR: usize = 4;
38+
39+
fn main() {
40+
let v = vec![100; 0usize];
41+
42+
for array in v.as_slice().array_windows::<{FOUR}>() {
43+
// println!("{:?}", array);
44+
}
45+
}

ices/62046.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(asm)]
2+
3+
struct ThreadContext {
4+
rsp: u64,
5+
r15: u64,
6+
}
7+
8+
fn gt_switch(new: *const ThreadContext) -> ! {
9+
unsafe {
10+
asm!("mov $1, $0" : "+r"("r15") : "*m"(&(*new).r15));
11+
asm!("mov $1, $0" : "+r"("rsp") : "*m"(&(*new).rsp));
12+
asm!("ret");
13+
std::hint::unreachable_unchecked()
14+
}
15+
}
16+
17+
fn main() {
18+
let ctx = ThreadContext{rsp: 0x80, r15: 0x88};
19+
20+
gt_switch(&ctx);
21+
}

ices/62200.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub trait SIterator {}
2+
3+
pub trait Ty<'a> {
4+
type V;
5+
}
6+
7+
struct FilterMap<F>(F);
8+
9+
impl<X, F> SIterator for FilterMap<F>
10+
where
11+
F: FnOnce(<X as Ty<'_>>::V) -> Option<<X as Ty<'_>>::V>
12+
{}
13+
14+
fn main() {}

ices/62222.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![feature(const_generics)]
2+
3+
use std::mem::MaybeUninit;
4+
5+
#[repr(transparent)]
6+
pub struct Vector<T, const N: usize>([T; N]);
7+
8+
impl<T, const N: usize> Vector<T, {N}> {
9+
pub fn x(self) -> T {
10+
let mut head = MaybeUninit::<T>::uninit();
11+
let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
12+
let mut from = MaybeUninit::new(self);
13+
let tailp: *mut T = unsafe { mem::transmute(&mut tail) };
14+
let fromp: *mut MaybeUninit<T> = unsafe { mem::transmute(&mut from) };
15+
unsafe {
16+
head.as_mut_ptr().write(
17+
fromp
18+
.replace(MaybeUninit::uninit())
19+
.assume_init()
20+
);
21+
}
22+
for i in 1..N {
23+
unsafe {
24+
tailp.add(i - 1).write(
25+
fromp
26+
.add(i)
27+
.replace(MaybeUninit::uninit())
28+
.assume_init()
29+
);
30+
}
31+
}
32+
unsafe { tail.assume_init(); } // Drop the tail
33+
unsafe { head.assume_init() }
34+
}
35+
}
36+
37+
fn main() {}

ices/62456.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![feature(const_generics)]
2+
3+
use std::fmt;
4+
5+
struct Builder<const N: usize> {
6+
items: [&'static str; N],
7+
}
8+
9+
fn new_builder() -> Builder<{0}> {
10+
return Builder{items: []};
11+
}
12+
13+
impl<const N: usize> Builder<{ N }> {
14+
fn append(self, value: &'static str) -> Builder<{ N + 1 }> {
15+
let mut new_items = [""; N + 1];
16+
new_items[..N].copy_from_slice(self.items);
17+
new_items[N] = value;
18+
return Builder { items: new_items };
19+
}
20+
21+
fn build(self) -> Final<{ N }> {
22+
return Final { items: self.items };
23+
}
24+
}
25+
26+
struct Final<const N: usize> {
27+
items: [&'static str; N],
28+
}
29+
30+
impl<const N: usize> fmt::Debug for Final<{ N }> {
31+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32+
f.debug_struct("Final")
33+
.field("items", &&self.items[..])
34+
.finish()
35+
}
36+
}
37+
38+
fn main() {
39+
let f = new_builder()
40+
.append("abc")
41+
.append("def")
42+
.append("ghi")
43+
.build();
44+
println!("f={:?}", f);
45+
}

ices/62480.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
'a: {
3+
|| break 'a
4+
}
5+
}

ices/62579.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(const_generics)]
2+
struct NoMatch;
3+
4+
fn foo<const T: NoMatch>() -> bool {
5+
return true
6+
}
7+
8+
fn main() {
9+
foo::<{NoMatch}>();
10+
}

0 commit comments

Comments
 (0)