]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/struct_constructors.rs
Update const_forget.rs
[rust.git] / src / test / incremental / hashes / struct_constructors.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for struct constructor expressions.
3
4 // The general pattern followed here is: Change one thing between rev1 and rev2
5 // and make sure that the hash has changed, then change nothing between rev2 and
6 // rev3 and make sure that the hash has not changed.
7
8 // build-pass (FIXME(62277): could be check-pass?)
9 // revisions: cfail1 cfail2 cfail3
10 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
11
12 #![allow(warnings)]
13 #![feature(rustc_attrs)]
14 #![crate_type="rlib"]
15
16
17 pub struct RegularStruct {
18     x: i32,
19     y: i64,
20     z: i16,
21 }
22
23 // Change field value (regular struct)
24 #[cfg(cfail1)]
25 pub fn change_field_value_regular_struct() -> RegularStruct {
26     RegularStruct {
27         x: 0,
28         y: 1,
29         z: 2,
30     }
31 }
32
33 #[cfg(not(cfail1))]
34 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
35 #[rustc_clean(cfg="cfail3")]
36 pub fn change_field_value_regular_struct() -> RegularStruct {
37     RegularStruct {
38         x: 0,
39         y: 2,
40         z: 2,
41     }
42 }
43
44
45
46 // Change field order (regular struct)
47 #[cfg(cfail1)]
48 pub fn change_field_order_regular_struct() -> RegularStruct {
49     RegularStruct {
50         x: 3,
51         y: 4,
52         z: 5,
53     }
54 }
55
56 #[cfg(not(cfail1))]
57 #[rustc_clean(cfg="cfail2", except="HirBody,typeck_tables_of")]
58 #[rustc_clean(cfg="cfail3")]
59 pub fn change_field_order_regular_struct() -> RegularStruct {
60     RegularStruct {
61         y: 4,
62         x: 3,
63         z: 5,
64     }
65 }
66
67
68
69 // Add field (regular struct)
70 #[cfg(cfail1)]
71 pub fn add_field_regular_struct() -> RegularStruct {
72     let struct1 = RegularStruct {
73         x: 3,
74         y: 4,
75         z: 5,
76     };
77
78     RegularStruct {
79         x: 7,
80         .. struct1
81     }
82 }
83
84 #[cfg(not(cfail1))]
85 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
86 #[rustc_clean(cfg="cfail3")]
87 pub fn add_field_regular_struct() -> RegularStruct {
88     let struct1 = RegularStruct {
89         x: 3,
90         y: 4,
91         z: 5,
92     };
93
94     RegularStruct {
95         x: 7,
96         y: 8,
97         .. struct1
98     }
99 }
100
101
102
103 // Change field label (regular struct)
104 #[cfg(cfail1)]
105 pub fn change_field_label_regular_struct() -> RegularStruct {
106     let struct1 = RegularStruct {
107         x: 3,
108         y: 4,
109         z: 5,
110     };
111
112     RegularStruct {
113         x: 7,
114         y: 9,
115         .. struct1
116     }
117 }
118
119 #[cfg(not(cfail1))]
120 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
121 #[rustc_clean(cfg="cfail3")]
122 pub fn change_field_label_regular_struct() -> RegularStruct {
123     let struct1 = RegularStruct {
124         x: 3,
125         y: 4,
126         z: 5,
127     };
128
129     RegularStruct {
130         x: 7,
131         z: 9,
132         .. struct1
133     }
134 }
135
136
137
138 pub struct RegularStruct2 {
139     x: i8,
140     y: i8,
141     z: i8,
142 }
143
144 // Change constructor path (regular struct)
145 #[cfg(cfail1)]
146 pub fn change_constructor_path_regular_struct() {
147     let _ = RegularStruct {
148         x: 0,
149         y: 1,
150         z: 2,
151     };
152 }
153
154 #[cfg(not(cfail1))]
155 #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,typeck_tables_of")]
156 #[rustc_clean(cfg="cfail3")]
157 pub fn change_constructor_path_regular_struct() {
158     let _ = RegularStruct2 {
159         x: 0,
160         y: 1,
161         z: 2,
162     };
163 }
164
165
166
167 // Change constructor path indirectly (regular struct)
168 pub mod change_constructor_path_indirectly_regular_struct {
169     #[cfg(cfail1)]
170     use super::RegularStruct as Struct;
171     #[cfg(not(cfail1))]
172     use super::RegularStruct2 as Struct;
173
174     #[rustc_clean(
175         cfg="cfail2",
176         except="fn_sig,Hir,HirBody,optimized_mir,mir_built,typeck_tables_of"
177     )]
178     #[rustc_clean(cfg="cfail3")]
179     pub fn function() -> Struct {
180         Struct {
181             x: 0,
182             y: 1,
183             z: 2,
184         }
185     }
186 }
187
188
189
190 pub struct TupleStruct(i32, i64, i16);
191
192 // Change field value (tuple struct)
193 #[cfg(cfail1)]
194 pub fn change_field_value_tuple_struct() -> TupleStruct {
195     TupleStruct(0, 1, 2)
196 }
197
198 #[cfg(not(cfail1))]
199 #[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built")]
200 #[rustc_clean(cfg="cfail3")]
201 pub fn change_field_value_tuple_struct() -> TupleStruct {
202     TupleStruct(0, 1, 3)
203 }
204
205
206
207 pub struct TupleStruct2(u16, u16, u16);
208
209 // Change constructor path (tuple struct)
210 #[cfg(cfail1)]
211 pub fn change_constructor_path_tuple_struct() {
212     let _ = TupleStruct(0, 1, 2);
213 }
214
215 #[cfg(not(cfail1))]
216 #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,typeck_tables_of")]
217 #[rustc_clean(cfg="cfail3")]
218 pub fn change_constructor_path_tuple_struct() {
219     let _ = TupleStruct2(0, 1, 2);
220 }
221
222
223
224 // Change constructor path indirectly (tuple struct)
225 pub mod change_constructor_path_indirectly_tuple_struct {
226     #[cfg(cfail1)]
227     use super::TupleStruct as Struct;
228     #[cfg(not(cfail1))]
229     use super::TupleStruct2 as Struct;
230
231     #[rustc_clean(
232         cfg="cfail2",
233         except="fn_sig,Hir,HirBody,optimized_mir,mir_built,typeck_tables_of"
234     )]
235     #[rustc_clean(cfg="cfail3")]
236     pub fn function() -> Struct {
237         Struct(0, 1, 2)
238     }
239 }