]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/trait_impls.rs
Rollup merge of #41141 - michaelwoerister:direct-metadata-ich-final, r=nikomatsakis
[rust.git] / src / test / incremental / hashes / trait_impls.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 // This test case tests the incremental compilation hash (ICH) implementation
13 // for let expressions.
14
15 // The general pattern followed here is: Change one thing between rev1 and rev2
16 // and make sure that the hash has changed, then change nothing between rev2 and
17 // rev3 and make sure that the hash has not changed.
18
19 // must-compile-successfully
20 // revisions: cfail1 cfail2 cfail3
21 // compile-flags: -Z query-dep-graph
22
23
24 #![allow(warnings)]
25 #![feature(rustc_attrs)]
26 #![feature(specialization)]
27 #![crate_type="rlib"]
28
29 struct Foo;
30
31 // Change Method Name -----------------------------------------------------------
32
33 #[cfg(cfail1)]
34 pub trait ChangeMethodNameTrait {
35     fn method_name();
36 }
37
38 #[cfg(cfail1)]
39 impl ChangeMethodNameTrait for Foo {
40     fn method_name() { }
41 }
42
43 #[cfg(not(cfail1))]
44 #[rustc_dirty(label="Hir", cfg="cfail2")]
45 #[rustc_clean(label="Hir", cfg="cfail3")]
46 #[rustc_metadata_dirty(cfg="cfail2")]
47 #[rustc_metadata_clean(cfg="cfail3")]
48 pub trait ChangeMethodNameTrait {
49     #[rustc_clean(label="Hir", cfg="cfail3")]
50     #[rustc_metadata_clean(cfg="cfail3")]
51     fn method_name2();
52 }
53
54 #[cfg(not(cfail1))]
55 #[rustc_dirty(label="Hir", cfg="cfail2")]
56 #[rustc_clean(label="Hir", cfg="cfail3")]
57 #[rustc_metadata_dirty(cfg="cfail2")]
58 #[rustc_metadata_clean(cfg="cfail3")]
59 impl ChangeMethodNameTrait for Foo {
60     #[rustc_clean(label="Hir", cfg="cfail3")]
61     #[rustc_metadata_clean(cfg="cfail3")]
62     fn method_name2() { }
63 }
64
65 // Change Method Body -----------------------------------------------------------
66 //
67 // This should affect the method itself, but not the impl.
68
69 pub trait ChangeMethodBodyTrait {
70     fn method_name();
71 }
72
73 #[cfg(cfail1)]
74 impl ChangeMethodBodyTrait for Foo {
75     fn method_name() { }
76 }
77
78 #[cfg(not(cfail1))]
79 #[rustc_clean(label="Hir", cfg="cfail2")]
80 #[rustc_clean(label="Hir", cfg="cfail3")]
81 #[rustc_metadata_clean(cfg="cfail2")]
82 #[rustc_metadata_clean(cfg="cfail3")]
83 impl ChangeMethodBodyTrait for Foo {
84     #[rustc_clean(label="Hir", cfg="cfail2")]
85     #[rustc_clean(label="Hir", cfg="cfail3")]
86     #[rustc_dirty(label="HirBody", cfg="cfail2")]
87     #[rustc_clean(label="HirBody", cfg="cfail3")]
88     #[rustc_metadata_clean(cfg="cfail2")]
89     #[rustc_metadata_clean(cfg="cfail3")]
90     fn method_name() {
91         ()
92     }
93 }
94
95 // Change Method Body (inlined fn) ---------------------------------------------
96 //
97 // This should affect the method itself, but not the impl.
98
99 pub trait ChangeMethodBodyTraitInlined {
100     fn method_name();
101 }
102
103 #[cfg(cfail1)]
104 impl ChangeMethodBodyTraitInlined for Foo {
105     #[inline]
106     fn method_name() { }
107 }
108
109 #[cfg(not(cfail1))]
110 #[rustc_clean(label="Hir", cfg="cfail2")]
111 #[rustc_clean(label="Hir", cfg="cfail3")]
112 #[rustc_metadata_clean(cfg="cfail2")]
113 #[rustc_metadata_clean(cfg="cfail3")]
114 impl ChangeMethodBodyTraitInlined for Foo {
115     #[rustc_clean(label="Hir", cfg="cfail2")]
116     #[rustc_clean(label="Hir", cfg="cfail3")]
117     #[rustc_dirty(label="HirBody", cfg="cfail2")]
118     #[rustc_clean(label="HirBody", cfg="cfail3")]
119     #[rustc_metadata_dirty(cfg="cfail2")]
120     #[rustc_metadata_clean(cfg="cfail3")]
121     #[inline]
122     fn method_name() {
123         panic!()
124     }
125 }
126
127 // Change Method Selfness ------------------------------------------------------
128
129 #[cfg(cfail1)]
130 pub trait ChangeMethodSelfnessTrait {
131     fn method_name();
132 }
133
134 #[cfg(cfail1)]
135 impl ChangeMethodSelfnessTrait for Foo {
136     fn method_name() { }
137 }
138
139 #[cfg(not(cfail1))]
140 pub trait ChangeMethodSelfnessTrait {
141     fn method_name(&self);
142 }
143
144 #[cfg(not(cfail1))]
145 #[rustc_dirty(label="Hir", cfg="cfail2")]
146 #[rustc_clean(label="Hir", cfg="cfail3")]
147 #[rustc_metadata_clean(cfg="cfail2")]
148 #[rustc_metadata_clean(cfg="cfail3")]
149 impl ChangeMethodSelfnessTrait for Foo {
150     #[rustc_dirty(label="Hir", cfg="cfail2")]
151     #[rustc_clean(label="Hir", cfg="cfail3")]
152     #[rustc_metadata_dirty(cfg="cfail2")]
153     #[rustc_metadata_clean(cfg="cfail3")]
154     fn method_name(&self) {
155         ()
156     }
157 }
158
159 // Change Method Selfness -----------------------------------------------------------
160
161 #[cfg(cfail1)]
162 pub trait RemoveMethodSelfnessTrait {
163     fn method_name(&self);
164 }
165
166 #[cfg(cfail1)]
167 impl RemoveMethodSelfnessTrait for Foo {
168     fn method_name(&self) { }
169 }
170
171 #[cfg(not(cfail1))]
172 pub trait RemoveMethodSelfnessTrait {
173     fn method_name();
174 }
175
176 #[cfg(not(cfail1))]
177 #[rustc_dirty(label="Hir", cfg="cfail2")]
178 #[rustc_clean(label="Hir", cfg="cfail3")]
179 #[rustc_metadata_clean(cfg="cfail2")]
180 #[rustc_metadata_clean(cfg="cfail3")]
181 impl RemoveMethodSelfnessTrait for Foo {
182     #[rustc_dirty(label="Hir", cfg="cfail2")]
183     #[rustc_clean(label="Hir", cfg="cfail3")]
184     #[rustc_metadata_dirty(cfg="cfail2")]
185     #[rustc_metadata_clean(cfg="cfail3")]
186     fn method_name() {}
187 }
188
189 // Change Method Selfmutness -----------------------------------------------------------
190
191 #[cfg(cfail1)]
192 pub trait ChangeMethodSelfmutnessTrait {
193     fn method_name(&self);
194 }
195
196 #[cfg(cfail1)]
197 impl ChangeMethodSelfmutnessTrait for Foo {
198     fn method_name(&self) { }
199 }
200
201 #[cfg(not(cfail1))]
202 pub trait ChangeMethodSelfmutnessTrait {
203     fn method_name(&mut self);
204 }
205
206 #[cfg(not(cfail1))]
207 #[rustc_clean(label="Hir", cfg="cfail2")]
208 #[rustc_clean(label="Hir", cfg="cfail3")]
209 #[rustc_metadata_clean(cfg="cfail2")]
210 #[rustc_metadata_clean(cfg="cfail3")]
211 impl ChangeMethodSelfmutnessTrait for Foo {
212     #[rustc_dirty(label="Hir", cfg="cfail2")]
213     #[rustc_clean(label="Hir", cfg="cfail3")]
214     #[rustc_metadata_dirty(cfg="cfail2")]
215     #[rustc_metadata_clean(cfg="cfail3")]
216     fn method_name(&mut self) {}
217 }
218
219 // Change item kind -----------------------------------------------------------
220
221 #[cfg(cfail1)]
222 pub trait ChangeItemKindTrait {
223     fn name();
224 }
225
226 #[cfg(cfail1)]
227 impl ChangeItemKindTrait for Foo {
228     fn name() { }
229 }
230
231 #[cfg(not(cfail1))]
232 pub trait ChangeItemKindTrait {
233     type name;
234 }
235
236 #[cfg(not(cfail1))]
237 #[rustc_dirty(label="Hir", cfg="cfail2")]
238 #[rustc_clean(label="Hir", cfg="cfail3")]
239 #[rustc_metadata_dirty(cfg="cfail2")]
240 #[rustc_metadata_clean(cfg="cfail3")]
241 impl ChangeItemKindTrait for Foo {
242     type name = ();
243 }
244
245 // Remove item -----------------------------------------------------------
246
247 #[cfg(cfail1)]
248 pub trait RemoveItemTrait {
249     type TypeName;
250     fn method_name();
251 }
252
253 #[cfg(cfail1)]
254 impl RemoveItemTrait for Foo {
255     type TypeName = ();
256     fn method_name() { }
257 }
258
259 #[cfg(not(cfail1))]
260 pub trait RemoveItemTrait {
261     type TypeName;
262 }
263
264 #[cfg(not(cfail1))]
265 #[rustc_dirty(label="Hir", cfg="cfail2")]
266 #[rustc_clean(label="Hir", cfg="cfail3")]
267 #[rustc_metadata_dirty(cfg="cfail2")]
268 #[rustc_metadata_clean(cfg="cfail3")]
269 impl RemoveItemTrait for Foo {
270     type TypeName = ();
271 }
272
273 // Add item -----------------------------------------------------------
274
275 #[cfg(cfail1)]
276 pub trait AddItemTrait {
277     type TypeName;
278 }
279
280 #[cfg(cfail1)]
281 impl AddItemTrait for Foo {
282     type TypeName = ();
283 }
284
285 #[cfg(not(cfail1))]
286 pub trait AddItemTrait {
287     type TypeName;
288     fn method_name();
289 }
290
291 #[cfg(not(cfail1))]
292 #[rustc_dirty(label="Hir", cfg="cfail2")]
293 #[rustc_clean(label="Hir", cfg="cfail3")]
294 #[rustc_metadata_dirty(cfg="cfail2")]
295 #[rustc_metadata_clean(cfg="cfail3")]
296 impl AddItemTrait for Foo {
297     type TypeName = ();
298     fn method_name() { }
299 }
300
301 // Change has-value -----------------------------------------------------------
302
303 #[cfg(cfail1)]
304 pub trait ChangeHasValueTrait {
305     fn method_name();
306 }
307
308 #[cfg(cfail1)]
309 impl ChangeHasValueTrait for Foo {
310     fn method_name() { }
311 }
312
313 #[cfg(not(cfail1))]
314 #[rustc_dirty(label="Hir", cfg="cfail2")]
315 #[rustc_clean(label="Hir", cfg="cfail3")]
316 #[rustc_metadata_clean(cfg="cfail2")]
317 #[rustc_metadata_clean(cfg="cfail3")]
318 pub trait ChangeHasValueTrait {
319     #[rustc_dirty(label="Hir", cfg="cfail2")]
320     #[rustc_clean(label="Hir", cfg="cfail3")]
321     #[rustc_metadata_dirty(cfg="cfail2")]
322     #[rustc_metadata_clean(cfg="cfail3")]
323     fn method_name() { }
324 }
325
326 #[cfg(not(cfail1))]
327 #[rustc_clean(label="Hir", cfg="cfail2")]
328 #[rustc_clean(label="Hir", cfg="cfail3")]
329 #[rustc_metadata_clean(cfg="cfail2")]
330 #[rustc_metadata_clean(cfg="cfail3")]
331 impl ChangeHasValueTrait for Foo {
332     fn method_name() { }
333 }
334
335 // Add default
336
337 pub trait AddDefaultTrait {
338     fn method_name();
339 }
340
341 #[cfg(cfail1)]
342 impl AddDefaultTrait for Foo {
343     fn method_name() { }
344 }
345
346 #[cfg(not(cfail1))]
347 #[rustc_dirty(label="Hir", cfg="cfail2")]
348 #[rustc_clean(label="Hir", cfg="cfail3")]
349 #[rustc_metadata_clean(cfg="cfail2")]
350 #[rustc_metadata_clean(cfg="cfail3")]
351 impl AddDefaultTrait for Foo {
352     #[rustc_dirty(label="Hir", cfg="cfail2")]
353     #[rustc_clean(label="Hir", cfg="cfail3")]
354     #[rustc_metadata_dirty(cfg="cfail2")]
355     #[rustc_metadata_clean(cfg="cfail3")]
356     default fn method_name() { }
357 }
358
359 // Add arguments
360
361 #[cfg(cfail1)]
362 pub trait AddArgumentTrait {
363     fn method_name(&self);
364 }
365
366 #[cfg(cfail1)]
367 impl AddArgumentTrait for Foo {
368     fn method_name(&self) { }
369 }
370
371 #[cfg(not(cfail1))]
372 pub trait AddArgumentTrait {
373     fn method_name(&self, x: u32);
374 }
375
376 #[cfg(not(cfail1))]
377 #[rustc_clean(label="Hir", cfg="cfail2")]
378 #[rustc_clean(label="Hir", cfg="cfail3")]
379 #[rustc_metadata_clean(cfg="cfail2")]
380 #[rustc_metadata_clean(cfg="cfail3")]
381 impl AddArgumentTrait for Foo {
382     #[rustc_dirty(label="Hir", cfg="cfail2")]
383     #[rustc_clean(label="Hir", cfg="cfail3")]
384     #[rustc_metadata_dirty(cfg="cfail2")]
385     #[rustc_metadata_clean(cfg="cfail3")]
386     fn method_name(&self, _x: u32) { }
387 }
388
389 // Change argument type
390
391 #[cfg(cfail1)]
392 pub trait ChangeArgumentTypeTrait {
393     fn method_name(&self, x: u32);
394 }
395
396 #[cfg(cfail1)]
397 impl ChangeArgumentTypeTrait for Foo {
398     fn method_name(&self, _x: u32) { }
399 }
400
401 #[cfg(not(cfail1))]
402 pub trait ChangeArgumentTypeTrait {
403     fn method_name(&self, x: char);
404 }
405
406 #[cfg(not(cfail1))]
407 #[rustc_clean(label="Hir", cfg="cfail2")]
408 #[rustc_clean(label="Hir", cfg="cfail3")]
409 #[rustc_metadata_clean(cfg="cfail2")]
410 #[rustc_metadata_clean(cfg="cfail3")]
411 impl ChangeArgumentTypeTrait for Foo {
412     #[rustc_dirty(label="Hir", cfg="cfail2")]
413     #[rustc_clean(label="Hir", cfg="cfail3")]
414     #[rustc_metadata_dirty(cfg="cfail2")]
415     #[rustc_metadata_clean(cfg="cfail3")]
416     fn method_name(&self, _x: char) { }
417 }
418
419
420
421 struct Bar<T>(T);
422
423 // Add Type Parameter To Impl --------------------------------------------------
424 trait AddTypeParameterToImpl<T> {
425     fn id(t: T) -> T;
426 }
427
428 #[cfg(cfail1)]
429 impl AddTypeParameterToImpl<u32> for Bar<u32> {
430     fn id(t: u32) -> u32 { t }
431 }
432
433 #[cfg(not(cfail1))]
434 #[rustc_dirty(label="Hir", cfg="cfail2")]
435 #[rustc_clean(label="Hir", cfg="cfail3")]
436 #[rustc_metadata_dirty(cfg="cfail2")]
437 #[rustc_metadata_clean(cfg="cfail3")]
438 impl<T> AddTypeParameterToImpl<T> for Bar<T> {
439     #[rustc_dirty(label="Hir", cfg="cfail2")]
440     #[rustc_clean(label="Hir", cfg="cfail3")]
441     #[rustc_metadata_dirty(cfg="cfail2")]
442     #[rustc_metadata_clean(cfg="cfail3")]
443     fn id(t: T) -> T { t }
444 }
445
446
447
448 // Change Self Type of Impl ----------------------------------------------------
449 trait ChangeSelfTypeOfImpl {
450     fn id(self) -> Self;
451 }
452
453 #[cfg(cfail1)]
454 impl ChangeSelfTypeOfImpl for u32 {
455     fn id(self) -> Self { self }
456 }
457
458 #[cfg(not(cfail1))]
459 #[rustc_dirty(label="Hir", cfg="cfail2")]
460 #[rustc_clean(label="Hir", cfg="cfail3")]
461 #[rustc_metadata_dirty(cfg="cfail2")]
462 #[rustc_metadata_clean(cfg="cfail3")]
463 impl ChangeSelfTypeOfImpl for u64 {
464     #[rustc_clean(label="Hir", cfg="cfail2")]
465     #[rustc_clean(label="Hir", cfg="cfail3")]
466     #[rustc_metadata_dirty(cfg="cfail2")]
467     #[rustc_metadata_clean(cfg="cfail3")]
468     fn id(self) -> Self { self }
469 }
470
471
472
473 // Add Lifetime Bound to Impl --------------------------------------------------
474 trait AddLifetimeBoundToImplParameter {
475     fn id(self) -> Self;
476 }
477
478 #[cfg(cfail1)]
479 impl<T> AddLifetimeBoundToImplParameter for T {
480     fn id(self) -> Self { self }
481 }
482
483 #[cfg(not(cfail1))]
484 #[rustc_dirty(label="Hir", cfg="cfail2")]
485 #[rustc_clean(label="Hir", cfg="cfail3")]
486 #[rustc_metadata_dirty(cfg="cfail2")]
487 #[rustc_metadata_clean(cfg="cfail3")]
488 impl<T: 'static> AddLifetimeBoundToImplParameter for T {
489     #[rustc_clean(label="Hir", cfg="cfail2")]
490     #[rustc_clean(label="Hir", cfg="cfail3")]
491     #[rustc_metadata_clean(cfg="cfail2")]
492     #[rustc_metadata_clean(cfg="cfail3")]
493     fn id(self) -> Self { self }
494 }
495
496
497
498 // Add Trait Bound to Impl Parameter -------------------------------------------
499 trait AddTraitBoundToImplParameter {
500     fn id(self) -> Self;
501 }
502
503 #[cfg(cfail1)]
504 impl<T> AddTraitBoundToImplParameter for T {
505     fn id(self) -> Self { self }
506 }
507
508 #[cfg(not(cfail1))]
509 #[rustc_dirty(label="Hir", cfg="cfail2")]
510 #[rustc_clean(label="Hir", cfg="cfail3")]
511 #[rustc_metadata_dirty(cfg="cfail2")]
512 #[rustc_metadata_clean(cfg="cfail3")]
513 impl<T: Clone> AddTraitBoundToImplParameter for T {
514     #[rustc_clean(label="Hir", cfg="cfail2")]
515     #[rustc_clean(label="Hir", cfg="cfail3")]
516     #[rustc_metadata_clean(cfg="cfail2")]
517     #[rustc_metadata_clean(cfg="cfail3")]
518     fn id(self) -> Self { self }
519 }
520
521
522
523 // Add #[no_mangle] to Method --------------------------------------------------
524 trait AddNoMangleToMethod {
525     fn add_no_mangle_to_method(&self) { }
526 }
527
528 #[cfg(cfail1)]
529 impl AddNoMangleToMethod for Foo {
530     fn add_no_mangle_to_method(&self) { }
531 }
532
533 #[cfg(not(cfail1))]
534 #[rustc_clean(label="Hir", cfg="cfail2")]
535 #[rustc_clean(label="Hir", cfg="cfail3")]
536 #[rustc_metadata_clean(cfg="cfail2")]
537 #[rustc_metadata_clean(cfg="cfail3")]
538 impl AddNoMangleToMethod for Foo {
539     #[rustc_dirty(label="Hir", cfg="cfail2")]
540     #[rustc_clean(label="Hir", cfg="cfail3")]
541     #[rustc_metadata_dirty(cfg="cfail2")]
542     #[rustc_metadata_clean(cfg="cfail3")]
543     #[no_mangle]
544     fn add_no_mangle_to_method(&self) { }
545 }
546
547
548 // Make Method #[inline] -------------------------------------------------------
549 trait MakeMethodInline {
550     fn make_method_inline(&self) -> u8 { 0 }
551 }
552
553 #[cfg(cfail1)]
554 impl MakeMethodInline for Foo {
555     fn make_method_inline(&self) -> u8 { 0 }
556 }
557
558 #[cfg(not(cfail1))]
559 #[rustc_clean(label="Hir", cfg="cfail2")]
560 #[rustc_clean(label="Hir", cfg="cfail3")]
561 #[rustc_metadata_clean(cfg="cfail2")]
562 #[rustc_metadata_clean(cfg="cfail3")]
563 impl MakeMethodInline for Foo {
564     #[rustc_dirty(label="Hir", cfg="cfail2")]
565     #[rustc_clean(label="Hir", cfg="cfail3")]
566     #[rustc_metadata_dirty(cfg="cfail2")]
567     #[rustc_metadata_clean(cfg="cfail3")]
568     #[inline]
569     fn make_method_inline(&self) -> u8 { 0 }
570 }