Skip to content

Commit a699859

Browse files
authored
Rollup merge of rust-lang#91065 - wesleywiser:add_incr_test, r=jackh726
Add test for evaluate_obligation: Ok(EvaluatedToOkModuloRegions) ICE Adds the minimial repro test case from rust-lang#85360. The fix for rust-lang#85360 was supposed to be rust-lang#85868 however the repro was resolved in the 2021-07-05 nightly while rust-lang#85868 didn't land until 2021-09-03. The reason for that is d34a3a4 **also** resolves that issue. To test if rust-lang#85868 actually fixes rust-lang#85360, I reverted d34a3a4 and found that rust-lang#85868 does indeed resolve rust-lang#85360. With that question resolved, add a test case to our incremental test suite for the original Ok(EvaluatedToOkModuloRegions) ICE. Thanks to ``@lqd`` for helping track this down!
2 parents 923f8da + 6fe13f6 commit a699859

File tree

3 files changed

+299
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)