]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/trait_impls.rs
Auto merge of #57119 - jethrogb:jb/sgx-os-mod2, r=joshtriplett
[rust.git] / src / test / incremental / hashes / trait_impls.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for let 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 // compile-pass
9 // revisions: cfail1 cfail2 cfail3
10 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
11
12
13 #![allow(warnings)]
14 #![feature(rustc_attrs)]
15 #![feature(specialization)]
16 #![crate_type="rlib"]
17
18 struct Foo;
19
20 // Change Method Name -----------------------------------------------------------
21
22 #[cfg(cfail1)]
23 pub trait ChangeMethodNameTrait {
24     fn method_name();
25 }
26
27 #[cfg(cfail1)]
28 impl ChangeMethodNameTrait for Foo {
29     fn method_name() { }
30 }
31
32 #[cfg(not(cfail1))]
33 #[rustc_dirty(label="Hir", cfg="cfail2")]
34 #[rustc_clean(label="Hir", cfg="cfail3")]
35 pub trait ChangeMethodNameTrait {
36     #[rustc_clean(label="Hir", cfg="cfail3")]
37     fn method_name2();
38 }
39
40 #[cfg(not(cfail1))]
41 #[rustc_dirty(label="Hir", cfg="cfail2")]
42 #[rustc_clean(label="Hir", cfg="cfail3")]
43 impl ChangeMethodNameTrait for Foo {
44     #[rustc_clean(label="Hir", cfg="cfail3")]
45     fn method_name2() { }
46 }
47
48 // Change Method Body -----------------------------------------------------------
49 //
50 // This should affect the method itself, but not the impl.
51
52 pub trait ChangeMethodBodyTrait {
53     fn method_name();
54 }
55
56 #[cfg(cfail1)]
57 impl ChangeMethodBodyTrait for Foo {
58     fn method_name() { }
59 }
60
61 #[cfg(not(cfail1))]
62 #[rustc_clean(label="Hir", cfg="cfail2")]
63 #[rustc_clean(label="Hir", cfg="cfail3")]
64 impl ChangeMethodBodyTrait for Foo {
65     #[rustc_clean(label="Hir", cfg="cfail2")]
66     #[rustc_clean(label="Hir", cfg="cfail3")]
67     #[rustc_dirty(label="HirBody", cfg="cfail2")]
68     #[rustc_clean(label="HirBody", cfg="cfail3")]
69     fn method_name() {
70         ()
71     }
72 }
73
74 // Change Method Body (inlined fn) ---------------------------------------------
75 //
76 // This should affect the method itself, but not the impl.
77
78 pub trait ChangeMethodBodyTraitInlined {
79     fn method_name();
80 }
81
82 #[cfg(cfail1)]
83 impl ChangeMethodBodyTraitInlined for Foo {
84     #[inline]
85     fn method_name() { }
86 }
87
88 #[cfg(not(cfail1))]
89 #[rustc_clean(label="Hir", cfg="cfail2")]
90 #[rustc_clean(label="Hir", cfg="cfail3")]
91 impl ChangeMethodBodyTraitInlined for Foo {
92     #[rustc_clean(label="Hir", cfg="cfail2")]
93     #[rustc_clean(label="Hir", cfg="cfail3")]
94     #[rustc_dirty(label="HirBody", cfg="cfail2")]
95     #[rustc_clean(label="HirBody", cfg="cfail3")]
96     #[inline]
97     fn method_name() {
98         panic!()
99     }
100 }
101
102 // Change Method Selfness ------------------------------------------------------
103
104 #[cfg(cfail1)]
105 pub trait ChangeMethodSelfnessTrait {
106     fn method_name();
107 }
108
109 #[cfg(cfail1)]
110 impl ChangeMethodSelfnessTrait for Foo {
111     fn method_name() { }
112 }
113
114 #[cfg(not(cfail1))]
115 pub trait ChangeMethodSelfnessTrait {
116     fn method_name(&self);
117 }
118
119 #[cfg(not(cfail1))]
120 #[rustc_dirty(label="Hir", cfg="cfail2")]
121 #[rustc_clean(label="Hir", cfg="cfail3")]
122 impl ChangeMethodSelfnessTrait for Foo {
123     #[rustc_dirty(label="Hir", cfg="cfail2")]
124     #[rustc_clean(label="Hir", cfg="cfail3")]
125     fn method_name(&self) {
126         ()
127     }
128 }
129
130 // Change Method Selfness -----------------------------------------------------------
131
132 #[cfg(cfail1)]
133 pub trait RemoveMethodSelfnessTrait {
134     fn method_name(&self);
135 }
136
137 #[cfg(cfail1)]
138 impl RemoveMethodSelfnessTrait for Foo {
139     fn method_name(&self) { }
140 }
141
142 #[cfg(not(cfail1))]
143 pub trait RemoveMethodSelfnessTrait {
144     fn method_name();
145 }
146
147 #[cfg(not(cfail1))]
148 #[rustc_dirty(label="Hir", cfg="cfail2")]
149 #[rustc_clean(label="Hir", cfg="cfail3")]
150 impl RemoveMethodSelfnessTrait for Foo {
151     #[rustc_dirty(label="Hir", cfg="cfail2")]
152     #[rustc_clean(label="Hir", cfg="cfail3")]
153     fn method_name() {}
154 }
155
156 // Change Method Selfmutness -----------------------------------------------------------
157
158 #[cfg(cfail1)]
159 pub trait ChangeMethodSelfmutnessTrait {
160     fn method_name(&self);
161 }
162
163 #[cfg(cfail1)]
164 impl ChangeMethodSelfmutnessTrait for Foo {
165     fn method_name(&self) { }
166 }
167
168 #[cfg(not(cfail1))]
169 pub trait ChangeMethodSelfmutnessTrait {
170     fn method_name(&mut self);
171 }
172
173 #[cfg(not(cfail1))]
174 #[rustc_clean(label="Hir", cfg="cfail2")]
175 #[rustc_clean(label="Hir", cfg="cfail3")]
176 impl ChangeMethodSelfmutnessTrait for Foo {
177     #[rustc_dirty(label="Hir", cfg="cfail2")]
178     #[rustc_clean(label="Hir", cfg="cfail3")]
179     fn method_name(&mut self) {}
180 }
181
182 // Change item kind -----------------------------------------------------------
183
184 #[cfg(cfail1)]
185 pub trait ChangeItemKindTrait {
186     fn name();
187 }
188
189 #[cfg(cfail1)]
190 impl ChangeItemKindTrait for Foo {
191     fn name() { }
192 }
193
194 #[cfg(not(cfail1))]
195 pub trait ChangeItemKindTrait {
196     type name;
197 }
198
199 #[cfg(not(cfail1))]
200 #[rustc_dirty(label="Hir", cfg="cfail2")]
201 #[rustc_clean(label="Hir", cfg="cfail3")]
202 impl ChangeItemKindTrait for Foo {
203     type name = ();
204 }
205
206 // Remove item -----------------------------------------------------------
207
208 #[cfg(cfail1)]
209 pub trait RemoveItemTrait {
210     type TypeName;
211     fn method_name();
212 }
213
214 #[cfg(cfail1)]
215 impl RemoveItemTrait for Foo {
216     type TypeName = ();
217     fn method_name() { }
218 }
219
220 #[cfg(not(cfail1))]
221 pub trait RemoveItemTrait {
222     type TypeName;
223 }
224
225 #[cfg(not(cfail1))]
226 #[rustc_dirty(label="Hir", cfg="cfail2")]
227 #[rustc_clean(label="Hir", cfg="cfail3")]
228 impl RemoveItemTrait for Foo {
229     type TypeName = ();
230 }
231
232 // Add item -----------------------------------------------------------
233
234 #[cfg(cfail1)]
235 pub trait AddItemTrait {
236     type TypeName;
237 }
238
239 #[cfg(cfail1)]
240 impl AddItemTrait for Foo {
241     type TypeName = ();
242 }
243
244 #[cfg(not(cfail1))]
245 pub trait AddItemTrait {
246     type TypeName;
247     fn method_name();
248 }
249
250 #[cfg(not(cfail1))]
251 #[rustc_dirty(label="Hir", cfg="cfail2")]
252 #[rustc_clean(label="Hir", cfg="cfail3")]
253 impl AddItemTrait for Foo {
254     type TypeName = ();
255     fn method_name() { }
256 }
257
258 // Change has-value -----------------------------------------------------------
259
260 #[cfg(cfail1)]
261 pub trait ChangeHasValueTrait {
262     fn method_name();
263 }
264
265 #[cfg(cfail1)]
266 impl ChangeHasValueTrait for Foo {
267     fn method_name() { }
268 }
269
270 #[cfg(not(cfail1))]
271 #[rustc_dirty(label="Hir", cfg="cfail2")]
272 #[rustc_clean(label="Hir", cfg="cfail3")]
273 pub trait ChangeHasValueTrait {
274     #[rustc_dirty(label="Hir", cfg="cfail2")]
275     #[rustc_clean(label="Hir", cfg="cfail3")]
276     fn method_name() { }
277 }
278
279 #[cfg(not(cfail1))]
280 #[rustc_clean(label="Hir", cfg="cfail2")]
281 #[rustc_clean(label="Hir", cfg="cfail3")]
282 impl ChangeHasValueTrait for Foo {
283     fn method_name() { }
284 }
285
286 // Add default
287
288 pub trait AddDefaultTrait {
289     fn method_name();
290 }
291
292 #[cfg(cfail1)]
293 impl AddDefaultTrait for Foo {
294     fn method_name() { }
295 }
296
297 #[cfg(not(cfail1))]
298 #[rustc_dirty(label="Hir", cfg="cfail2")]
299 #[rustc_clean(label="Hir", cfg="cfail3")]
300 impl AddDefaultTrait for Foo {
301     #[rustc_dirty(label="Hir", cfg="cfail2")]
302     #[rustc_clean(label="Hir", cfg="cfail3")]
303     default fn method_name() { }
304 }
305
306 // Add arguments
307
308 #[cfg(cfail1)]
309 pub trait AddArgumentTrait {
310     fn method_name(&self);
311 }
312
313 #[cfg(cfail1)]
314 impl AddArgumentTrait for Foo {
315     fn method_name(&self) { }
316 }
317
318 #[cfg(not(cfail1))]
319 pub trait AddArgumentTrait {
320     fn method_name(&self, x: u32);
321 }
322
323 #[cfg(not(cfail1))]
324 #[rustc_clean(label="Hir", cfg="cfail2")]
325 #[rustc_clean(label="Hir", cfg="cfail3")]
326 impl AddArgumentTrait for Foo {
327     #[rustc_dirty(label="Hir", cfg="cfail2")]
328     #[rustc_clean(label="Hir", cfg="cfail3")]
329     fn method_name(&self, _x: u32) { }
330 }
331
332 // Change argument type
333
334 #[cfg(cfail1)]
335 pub trait ChangeArgumentTypeTrait {
336     fn method_name(&self, x: u32);
337 }
338
339 #[cfg(cfail1)]
340 impl ChangeArgumentTypeTrait for Foo {
341     fn method_name(&self, _x: u32) { }
342 }
343
344 #[cfg(not(cfail1))]
345 pub trait ChangeArgumentTypeTrait {
346     fn method_name(&self, x: char);
347 }
348
349 #[cfg(not(cfail1))]
350 #[rustc_clean(label="Hir", cfg="cfail2")]
351 #[rustc_clean(label="Hir", cfg="cfail3")]
352 impl ChangeArgumentTypeTrait for Foo {
353     #[rustc_dirty(label="Hir", cfg="cfail2")]
354     #[rustc_clean(label="Hir", cfg="cfail3")]
355     fn method_name(&self, _x: char) { }
356 }
357
358
359
360 struct Bar<T>(T);
361
362 // Add Type Parameter To Impl --------------------------------------------------
363 trait AddTypeParameterToImpl<T> {
364     fn id(t: T) -> T;
365 }
366
367 #[cfg(cfail1)]
368 impl AddTypeParameterToImpl<u32> for Bar<u32> {
369     fn id(t: u32) -> u32 { t }
370 }
371
372 #[cfg(not(cfail1))]
373 #[rustc_dirty(label="Hir", cfg="cfail2")]
374 #[rustc_clean(label="Hir", cfg="cfail3")]
375 impl<T> AddTypeParameterToImpl<T> for Bar<T> {
376     #[rustc_dirty(label="Hir", cfg="cfail2")]
377     #[rustc_clean(label="Hir", cfg="cfail3")]
378     fn id(t: T) -> T { t }
379 }
380
381
382
383 // Change Self Type of Impl ----------------------------------------------------
384 trait ChangeSelfTypeOfImpl {
385     fn id(self) -> Self;
386 }
387
388 #[cfg(cfail1)]
389 impl ChangeSelfTypeOfImpl for u32 {
390     fn id(self) -> Self { self }
391 }
392
393 #[cfg(not(cfail1))]
394 #[rustc_dirty(label="Hir", cfg="cfail2")]
395 #[rustc_clean(label="Hir", cfg="cfail3")]
396 impl ChangeSelfTypeOfImpl for u64 {
397     #[rustc_clean(label="Hir", cfg="cfail2")]
398     #[rustc_clean(label="Hir", cfg="cfail3")]
399     fn id(self) -> Self { self }
400 }
401
402
403
404 // Add Lifetime Bound to Impl --------------------------------------------------
405 trait AddLifetimeBoundToImplParameter {
406     fn id(self) -> Self;
407 }
408
409 #[cfg(cfail1)]
410 impl<T> AddLifetimeBoundToImplParameter for T {
411     fn id(self) -> Self { self }
412 }
413
414 #[cfg(not(cfail1))]
415 #[rustc_dirty(label="Hir", cfg="cfail2")]
416 #[rustc_clean(label="Hir", cfg="cfail3")]
417 impl<T: 'static> AddLifetimeBoundToImplParameter for T {
418     #[rustc_clean(label="Hir", cfg="cfail2")]
419     #[rustc_clean(label="Hir", cfg="cfail3")]
420     fn id(self) -> Self { self }
421 }
422
423
424
425 // Add Trait Bound to Impl Parameter -------------------------------------------
426 trait AddTraitBoundToImplParameter {
427     fn id(self) -> Self;
428 }
429
430 #[cfg(cfail1)]
431 impl<T> AddTraitBoundToImplParameter for T {
432     fn id(self) -> Self { self }
433 }
434
435 #[cfg(not(cfail1))]
436 #[rustc_dirty(label="Hir", cfg="cfail2")]
437 #[rustc_clean(label="Hir", cfg="cfail3")]
438 impl<T: Clone> AddTraitBoundToImplParameter for T {
439     #[rustc_clean(label="Hir", cfg="cfail2")]
440     #[rustc_clean(label="Hir", cfg="cfail3")]
441     fn id(self) -> Self { self }
442 }
443
444
445
446 // Add #[no_mangle] to Method --------------------------------------------------
447 trait AddNoMangleToMethod {
448     fn add_no_mangle_to_method(&self) { }
449 }
450
451 #[cfg(cfail1)]
452 impl AddNoMangleToMethod for Foo {
453     fn add_no_mangle_to_method(&self) { }
454 }
455
456 #[cfg(not(cfail1))]
457 #[rustc_clean(label="Hir", cfg="cfail2")]
458 #[rustc_clean(label="Hir", cfg="cfail3")]
459 impl AddNoMangleToMethod for Foo {
460     #[rustc_dirty(label="Hir", cfg="cfail2")]
461     #[rustc_clean(label="Hir", cfg="cfail3")]
462     #[no_mangle]
463     fn add_no_mangle_to_method(&self) { }
464 }
465
466
467 // Make Method #[inline] -------------------------------------------------------
468 trait MakeMethodInline {
469     fn make_method_inline(&self) -> u8 { 0 }
470 }
471
472 #[cfg(cfail1)]
473 impl MakeMethodInline for Foo {
474     fn make_method_inline(&self) -> u8 { 0 }
475 }
476
477 #[cfg(not(cfail1))]
478 #[rustc_clean(label="Hir", cfg="cfail2")]
479 #[rustc_clean(label="Hir", cfg="cfail3")]
480 impl MakeMethodInline for Foo {
481     #[rustc_dirty(label="Hir", cfg="cfail2")]
482     #[rustc_clean(label="Hir", cfg="cfail3")]
483     #[inline]
484     fn make_method_inline(&self) -> u8 { 0 }
485 }