]> git.lizzy.rs Git - rust.git/blob - tests/incremental/issue-85360-eval-obligation-ice.rs
Rollup merge of #106441 - mllken:abstract-socket-noref, r=joshtriplett
[rust.git] / tests / incremental / issue-85360-eval-obligation-ice.rs
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 }