Skip to content

Commit 98e9b32

Browse files
committed
Add test with #[rustc_evaluate_where_clauses]
As suggested via reviewer feedback.
1 parent 14c6193 commit 98e9b32

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

src/test/incremental/issue-85360-eval-obligation-ice.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// revisions:cfail1 cfail2
2-
// compile-flags: --crate-type=lib --edition=2021
2+
//[cfail1] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=not-loaded
3+
//[cfail2] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=loaded
34
// build-pass
45

56
use core::any::Any;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// compile-flags: --edition=2021
2+
3+
#![feature(rustc_attrs)]
4+
5+
use core::any::Any;
6+
use core::marker::PhantomData;
7+
8+
fn main() {
9+
test::<MaskedStorage<GenericComp<Pos>>>(make());
10+
//~^ ERROR evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
11+
//~| ERROR evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
12+
}
13+
14+
#[rustc_evaluate_where_clauses]
15+
fn test<T: Sized>(_: T) {}
16+
17+
fn make<T>() -> T {
18+
todo!()
19+
}
20+
21+
struct DerefWrap<T>(T);
22+
23+
impl<T> core::ops::Deref for DerefWrap<T> {
24+
type Target = T;
25+
fn deref(&self) -> &Self::Target {
26+
&self.0
27+
}
28+
}
29+
30+
struct Storage<T, D> {
31+
phantom: PhantomData<(T, D)>,
32+
}
33+
34+
type ReadStorage<T> = Storage<T, DerefWrap<MaskedStorage<T>>>;
35+
36+
pub trait Component {
37+
type Storage;
38+
}
39+
40+
struct VecStorage;
41+
42+
struct Pos;
43+
44+
impl Component for Pos {
45+
type Storage = VecStorage;
46+
}
47+
48+
struct GenericComp<T> {
49+
_t: T,
50+
}
51+
52+
impl<T: 'static> Component for GenericComp<T> {
53+
type Storage = VecStorage;
54+
}
55+
struct ReadData {
56+
pos_interpdata: ReadStorage<GenericComp<Pos>>,
57+
}
58+
59+
trait System {
60+
type SystemData;
61+
62+
fn run(data: Self::SystemData, any: Box<dyn Any>);
63+
}
64+
65+
struct Sys;
66+
67+
impl System for Sys {
68+
type SystemData = (ReadData, ReadStorage<Pos>);
69+
70+
fn run((data, pos): Self::SystemData, any: Box<dyn Any>) {
71+
<ReadStorage<GenericComp<Pos>> as SystemData>::setup(any);
72+
73+
ParJoin::par_join((&pos, &data.pos_interpdata));
74+
}
75+
}
76+
77+
trait ParJoin {
78+
fn par_join(self)
79+
where
80+
Self: Sized,
81+
{
82+
}
83+
}
84+
85+
impl<'a, T, D> ParJoin for &'a Storage<T, D>
86+
where
87+
T: Component,
88+
D: core::ops::Deref<Target = MaskedStorage<T>>,
89+
T::Storage: Sync,
90+
{
91+
}
92+
93+
impl<A, B> ParJoin for (A, B)
94+
where
95+
A: ParJoin,
96+
B: ParJoin,
97+
{
98+
}
99+
100+
pub trait SystemData {
101+
fn setup(any: Box<dyn Any>);
102+
}
103+
104+
impl<T: 'static> SystemData for ReadStorage<T>
105+
where
106+
T: Component,
107+
{
108+
fn setup(any: Box<dyn Any>) {
109+
let storage: &MaskedStorage<T> = any.downcast_ref().unwrap();
110+
111+
<dyn Any as CastFrom<MaskedStorage<T>>>::cast(&storage);
112+
}
113+
}
114+
115+
pub struct MaskedStorage<T: Component> {
116+
_inner: T::Storage,
117+
}
118+
119+
pub unsafe trait CastFrom<T> {
120+
fn cast(t: &T) -> &Self;
121+
}
122+
123+
unsafe impl<T> CastFrom<T> for dyn Any
124+
where
125+
T: Any + 'static,
126+
{
127+
fn cast(t: &T) -> &Self {
128+
t
129+
}
130+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
2+
--> $DIR/issue-85360-eval-obligation-ice.rs:9:5
3+
|
4+
LL | test::<MaskedStorage<GenericComp<Pos>>>(make());
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | fn test<T: Sized>(_: T) {}
8+
| - predicate
9+
10+
error: evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
11+
--> $DIR/issue-85360-eval-obligation-ice.rs:9:5
12+
|
13+
LL | test::<MaskedStorage<GenericComp<Pos>>>(make());
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
...
16+
LL | fn test<T: Sized>(_: T) {}
17+
| ----- predicate
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)