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