]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/issue-85360-eval-obligation-ice.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / traits / issue-85360-eval-obligation-ice.rs
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 }