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

Commit 6d389a1

Browse files
authored
Merge pull request #1520 from JohnTitor/add-ices-20230303
2 parents e9bbb08 + c18f844 commit 6d389a1

File tree

8 files changed

+257
-0
lines changed

8 files changed

+257
-0
lines changed

ices/103507.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![feature(type_alias_impl_trait)]
2+
#![feature(const_trait_impl)]
3+
#![feature(const_refs_to_cell)]
4+
#![feature(inline_const)]
5+
6+
use std::marker::Destruct;
7+
8+
trait T {
9+
type Item;
10+
}
11+
12+
type Alias<'a> = impl T<Item = &'a ()>;
13+
14+
struct S;
15+
impl<'a> T for &'a S {
16+
type Item = &'a ();
17+
}
18+
19+
const fn filter_positive<'a>() -> &'a Alias<'a> {
20+
&&S
21+
}
22+
23+
const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
24+
fun(filter_positive());
25+
}
26+
27+
const fn foo(_: &Alias<'_>) {}
28+
29+
const BAR: () = {
30+
with_positive(foo);
31+
};
32+
33+
fn main() {}

ices/106874.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::marker::PhantomData;
2+
use std::rc::Rc;
3+
4+
pub fn func<V, F: Fn(&mut V)>(f: F) -> A<impl X> {
5+
A(B(C::new(D::new(move |st| f(st)))))
6+
}
7+
8+
trait X {}
9+
trait Y {
10+
type V;
11+
}
12+
13+
struct A<T>(T);
14+
15+
struct B<T>(Rc<T>);
16+
impl<T> X for B<T> {}
17+
18+
struct C<T: Y>(T::V);
19+
impl<T: Y> C<T> {
20+
fn new(_: T) -> Rc<Self> {
21+
todo!()
22+
}
23+
}
24+
struct D<V, F>(F, PhantomData<fn(&mut V)>);
25+
26+
impl<V, F> D<V, F> {
27+
fn new(_: F) -> Self {
28+
todo!()
29+
}
30+
}
31+
impl<V, F: Fn(&mut V)> Y for D<V, F> {
32+
type V = V;
33+
}
34+
35+
fn main() {}

ices/107228.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
rustc -Zvalidate-mir --crate-type=lib - <<'EOF'
4+
5+
#![feature(specialization)]
6+
7+
pub(crate) trait SpecTrait {
8+
type Assoc;
9+
}
10+
11+
impl<C> SpecTrait for C {
12+
default type Assoc = Vec<Self>;
13+
}
14+
15+
pub(crate) struct AssocWrap<C: SpecTrait> {
16+
_assoc: C::Assoc,
17+
}
18+
19+
fn instantiate<C: SpecTrait>() -> AssocWrap<C> {
20+
loop {}
21+
}
22+
23+
pub fn trigger() {
24+
instantiate::<()>();
25+
}
26+
EOF

ices/108271-1.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub trait TraitWAssocConst<T> {
2+
const A: T;
3+
}
4+
5+
fn foo<T, B: TraitWAssocConst<T, A = { 1 }>>() {}
6+
7+
fn main() {}

ices/108271-2.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
pub trait TraitWAssocConst {
5+
const A: dyn TraitWAssocConst<A = 0>;
6+
}
7+
8+
fn bar<A: TraitWAssocConst<A = 0>>() {}
9+
10+
fn main() {}

ices/108329.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
pub enum Restriction<const V: bool = true> {}
5+
pub trait Valid {}
6+
7+
impl Valid for Restriction<true> {}
8+
9+
/**
10+
a circular buffer
11+
*/
12+
pub struct CircularBuffer<T, const S: usize> {
13+
buffer: Vec<T>,
14+
index: usize,
15+
}
16+
17+
impl<T, const S: usize> CircularBuffer<T, { S }>
18+
where
19+
Restriction<{ S > 0 }>: Valid,
20+
{
21+
/**
22+
create a new [`CircularBuffer`] instance
23+
*/
24+
pub fn new() -> Self {
25+
Self {
26+
buffer: Vec::with_capacity(S),
27+
index: S - 1,
28+
}
29+
}
30+
31+
/**
32+
push a value onto the buffer
33+
*/
34+
pub fn push(&mut self, value: T) {
35+
self.index = self.index.checked_add(1).unwrap_or(0) % S;
36+
match self.count() < self.capacity() {
37+
true => self.buffer.insert(self.index, value),
38+
false => self.buffer[self.index] = value,
39+
}
40+
}
41+
42+
/**
43+
push a value onto the buffer
44+
*/
45+
pub fn pop(&mut self) -> Result<T, CircularBufferError> {
46+
if self.count() == 0 {
47+
Err(CircularBufferError::Underflow)?
48+
}
49+
50+
let old = self.buffer.remove(self.index);
51+
self.index = self.index.checked_sub(1).unwrap_or(S - 1);
52+
Ok(old)
53+
}
54+
}
55+
56+
impl<T, const S: usize> CircularBuffer<T, { S }> {
57+
/**
58+
returns the current count of the buffer
59+
*/
60+
pub fn count(&self) -> usize {
61+
self.buffer.len()
62+
}
63+
64+
/**
65+
returns the max capacity of the buffer
66+
*/
67+
pub const fn capacity(&self) -> usize {
68+
S
69+
}
70+
}
71+
72+
impl<T, const S: usize> CircularBuffer<T, { S }>
73+
where
74+
T: Clone,
75+
{
76+
/**
77+
take the values in a vec, leaving an empty buffer
78+
*/
79+
pub fn take(&mut self) -> Vec<T> {
80+
let mut buf = Vec::with_capacity(self.buffer.len());
81+
buf.copy_from_slice(self.buffer[..]);
82+
self.index = S - 1;
83+
buf
84+
}
85+
86+
/**
87+
returns true if the buffer is empty
88+
*/
89+
pub fn is_empty(&self) -> bool {
90+
self.buffer.is_empty()
91+
}
92+
}
93+
94+
#[derive(Debug, PartialEq)]
95+
pub enum CircularBufferError {
96+
/// attempted to pop when buffer is empty
97+
Underflow,
98+
}
99+
100+
fn main() {}

ices/108334.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
cat > Cargo.toml <<'EOF'
4+
[package]
5+
name = "kandis"
6+
version = "0.0.1"
7+
edition = "2021"
8+
EOF
9+
10+
mkdir -p src
11+
12+
cat > src/main.rs <<'EOF'
13+
mod foo_1;
14+
15+
/// Hello [`Bar`]. // crash
16+
pub use foo_1::Bar;
17+
EOF
18+
19+
cat > src/foo_1.rs <<'EOF'
20+
pub trait Bar {}
21+
EOF
22+
23+
cargo doc

ices/79495.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
cat > out.rs <<'EOF'
4+
#![feature(arbitrary_enum_discriminant, generic_const_exprs, core_intrinsics)]
5+
6+
extern crate core;
7+
use core::intrinsics::discriminant_value;
8+
9+
#[repr(usize)]
10+
enum MyWeirdOption<T> {
11+
None = 0,
12+
Some(T) = std::mem::size_of::<T>(),
13+
//~^ ERROR constant expression depends on a generic parameter
14+
}
15+
16+
fn main() {
17+
assert_eq!(discriminant_value(&MyWeirdOption::<u8>::None), 0);
18+
assert_eq!(discriminant_value(&MyWeirdOption::Some(0u8)), 1);
19+
}
20+
21+
EOF
22+
23+
rustdoc --edition=2021 out.rs

0 commit comments

Comments
 (0)