]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/deriving-associated-types.rs
Rollup merge of #105784 - yanns:update_stdarch, r=Amanieu
[rust.git] / src / tools / miri / tests / pass / deriving-associated-types.rs
1 pub trait DeclaredTrait {
2     type Type;
3 }
4
5 impl DeclaredTrait for i32 {
6     type Type = i32;
7 }
8
9 pub trait WhereTrait {
10     type Type;
11 }
12
13 impl WhereTrait for i32 {
14     type Type = i32;
15 }
16
17 // Make sure we don't add a bound that just shares a name with an associated
18 // type.
19 pub mod module {
20     pub type Type = i32;
21 }
22
23 #[derive(PartialEq, Debug)]
24 struct PrivateStruct<T>(T);
25
26 #[derive(PartialEq, Debug)]
27 struct TupleStruct<A, B: DeclaredTrait, C>(
28     module::Type,
29     Option<module::Type>,
30     A,
31     PrivateStruct<A>,
32     B,
33     B::Type,
34     Option<B::Type>,
35     <B as DeclaredTrait>::Type,
36     Option<<B as DeclaredTrait>::Type>,
37     C,
38     C::Type,
39     Option<C::Type>,
40     <C as WhereTrait>::Type,
41     Option<<C as WhereTrait>::Type>,
42     <i32 as DeclaredTrait>::Type,
43 )
44 where
45     C: WhereTrait;
46
47 #[derive(PartialEq, Debug)]
48 pub struct Struct<A, B: DeclaredTrait, C>
49 where
50     C: WhereTrait,
51 {
52     m1: module::Type,
53     m2: Option<module::Type>,
54     a1: A,
55     a2: PrivateStruct<A>,
56     b: B,
57     b1: B::Type,
58     b2: Option<B::Type>,
59     b3: <B as DeclaredTrait>::Type,
60     b4: Option<<B as DeclaredTrait>::Type>,
61     c: C,
62     c1: C::Type,
63     c2: Option<C::Type>,
64     c3: <C as WhereTrait>::Type,
65     c4: Option<<C as WhereTrait>::Type>,
66     d: <i32 as DeclaredTrait>::Type,
67 }
68
69 #[derive(PartialEq, Debug)]
70 enum Enum<A, B: DeclaredTrait, C>
71 where
72     C: WhereTrait,
73 {
74     Unit,
75     Seq(
76         module::Type,
77         Option<module::Type>,
78         A,
79         PrivateStruct<A>,
80         B,
81         B::Type,
82         Option<B::Type>,
83         <B as DeclaredTrait>::Type,
84         Option<<B as DeclaredTrait>::Type>,
85         C,
86         C::Type,
87         Option<C::Type>,
88         <C as WhereTrait>::Type,
89         Option<<C as WhereTrait>::Type>,
90         <i32 as DeclaredTrait>::Type,
91     ),
92     Map {
93         m1: module::Type,
94         m2: Option<module::Type>,
95         a1: A,
96         a2: PrivateStruct<A>,
97         b: B,
98         b1: B::Type,
99         b2: Option<B::Type>,
100         b3: <B as DeclaredTrait>::Type,
101         b4: Option<<B as DeclaredTrait>::Type>,
102         c: C,
103         c1: C::Type,
104         c2: Option<C::Type>,
105         c3: <C as WhereTrait>::Type,
106         c4: Option<<C as WhereTrait>::Type>,
107         d: <i32 as DeclaredTrait>::Type,
108     },
109 }
110
111 fn main() {
112     let e: Enum<i32, i32, i32> =
113         Enum::Seq(0, None, 0, PrivateStruct(0), 0, 0, None, 0, None, 0, 0, None, 0, None, 0);
114     assert_eq!(e, e);
115
116     let e: Enum<i32, i32, i32> = Enum::Map {
117         m1: 0,
118         m2: None,
119         a1: 0,
120         a2: PrivateStruct(0),
121         b: 0,
122         b1: 0,
123         b2: None,
124         b3: 0,
125         b4: None,
126         c: 0,
127         c1: 0,
128         c2: None,
129         c3: 0,
130         c4: None,
131         d: 0,
132     };
133     assert_eq!(e, e);
134     let e: TupleStruct<i32, i32, i32> =
135         TupleStruct(0, None, 0, PrivateStruct(0), 0, 0, None, 0, None, 0, 0, None, 0, None, 0);
136     assert_eq!(e, e);
137
138     let e: Struct<i32, i32, i32> = Struct {
139         m1: 0,
140         m2: None,
141         a1: 0,
142         a2: PrivateStruct(0),
143         b: 0,
144         b1: 0,
145         b2: None,
146         b3: 0,
147         b4: None,
148         c: 0,
149         c1: 0,
150         c2: None,
151         c3: 0,
152         c4: None,
153         d: 0,
154     };
155     assert_eq!(e, e);
156
157     let e = Enum::Unit::<i32, i32, i32>;
158     assert_eq!(e, e);
159 }