]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/trait_impls.rs
Rollup merge of #41087 - estebank:tuple-float-index, r=arielb1
[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         ()
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_dirty(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_dirty(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 }
190
191 // Change Method Selfmutness -----------------------------------------------------------
192
193 #[cfg(cfail1)]
194 pub trait ChangeMethodSelfmutnessTrait {
195     fn method_name(&self);
196 }
197
198 #[cfg(cfail1)]
199 impl ChangeMethodSelfmutnessTrait for Foo {
200     fn method_name(&self) { }
201 }
202
203 #[cfg(not(cfail1))]
204 pub trait ChangeMethodSelfmutnessTrait {
205     fn method_name(&mut self);
206 }
207
208 #[cfg(not(cfail1))]
209 #[rustc_clean(label="Hir", cfg="cfail2")]
210 #[rustc_clean(label="Hir", cfg="cfail3")]
211 #[rustc_metadata_dirty(cfg="cfail2")]
212 #[rustc_metadata_clean(cfg="cfail3")]
213 impl ChangeMethodSelfmutnessTrait for Foo {
214     #[rustc_dirty(label="Hir", cfg="cfail2")]
215     #[rustc_clean(label="Hir", cfg="cfail3")]
216     #[rustc_metadata_dirty(cfg="cfail2")]
217     #[rustc_metadata_clean(cfg="cfail3")]
218     fn method_name(&mut self) {
219         ()
220     }
221 }
222
223 // Change item kind -----------------------------------------------------------
224
225 #[cfg(cfail1)]
226 pub trait ChangeItemKindTrait {
227     fn name();
228 }
229
230 #[cfg(cfail1)]
231 impl ChangeItemKindTrait for Foo {
232     fn name() { }
233 }
234
235 #[cfg(not(cfail1))]
236 pub trait ChangeItemKindTrait {
237     type name;
238 }
239
240 #[cfg(not(cfail1))]
241 #[rustc_dirty(label="Hir", cfg="cfail2")]
242 #[rustc_clean(label="Hir", cfg="cfail3")]
243 #[rustc_metadata_dirty(cfg="cfail2")]
244 #[rustc_metadata_clean(cfg="cfail3")]
245 impl ChangeItemKindTrait for Foo {
246     type name = ();
247 }
248
249 // Remove item -----------------------------------------------------------
250
251 #[cfg(cfail1)]
252 pub trait RemoveItemTrait {
253     type TypeName;
254     fn method_name();
255 }
256
257 #[cfg(cfail1)]
258 impl RemoveItemTrait for Foo {
259     type TypeName = ();
260     fn method_name() { }
261 }
262
263 #[cfg(not(cfail1))]
264 pub trait RemoveItemTrait {
265     type TypeName;
266 }
267
268 #[cfg(not(cfail1))]
269 #[rustc_dirty(label="Hir", cfg="cfail2")]
270 #[rustc_clean(label="Hir", cfg="cfail3")]
271 #[rustc_metadata_dirty(cfg="cfail2")]
272 #[rustc_metadata_clean(cfg="cfail3")]
273 impl RemoveItemTrait for Foo {
274     type TypeName = ();
275 }
276
277 // Add item -----------------------------------------------------------
278
279 #[cfg(cfail1)]
280 pub trait AddItemTrait {
281     type TypeName;
282 }
283
284 #[cfg(cfail1)]
285 impl AddItemTrait for Foo {
286     type TypeName = ();
287 }
288
289 #[cfg(not(cfail1))]
290 pub trait AddItemTrait {
291     type TypeName;
292     fn method_name();
293 }
294
295 #[cfg(not(cfail1))]
296 #[rustc_dirty(label="Hir", cfg="cfail2")]
297 #[rustc_clean(label="Hir", cfg="cfail3")]
298 #[rustc_metadata_dirty(cfg="cfail2")]
299 #[rustc_metadata_clean(cfg="cfail3")]
300 impl AddItemTrait for Foo {
301     type TypeName = ();
302     fn method_name() { }
303 }
304
305 // Change has-value -----------------------------------------------------------
306
307 #[cfg(cfail1)]
308 pub trait ChangeHasValueTrait {
309     fn method_name();
310 }
311
312 #[cfg(cfail1)]
313 impl ChangeHasValueTrait for Foo {
314     fn method_name() { }
315 }
316
317 #[cfg(not(cfail1))]
318 #[rustc_dirty(label="Hir", cfg="cfail2")]
319 #[rustc_clean(label="Hir", cfg="cfail3")]
320 #[rustc_metadata_dirty(cfg="cfail2")]
321 #[rustc_metadata_clean(cfg="cfail3")]
322 pub trait ChangeHasValueTrait {
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_dirty(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_dirty(cfg="cfail2")]
350 #[rustc_metadata_clean(cfg="cfail3")]
351 impl AddDefaultTrait for Foo {
352     default fn method_name() { }
353 }
354
355 // Remove default
356
357 pub trait RemoveDefaultTrait {
358     fn method_name();
359 }
360
361 #[cfg(cfail1)]
362 impl RemoveDefaultTrait for Foo {
363     default fn method_name() { }
364 }
365
366 #[cfg(not(cfail1))]
367 #[rustc_dirty(label="Hir", cfg="cfail2")]
368 #[rustc_clean(label="Hir", cfg="cfail3")]
369 #[rustc_metadata_dirty(cfg="cfail2")]
370 #[rustc_metadata_clean(cfg="cfail3")]
371 impl RemoveDefaultTrait for Foo {
372     fn method_name() { }
373 }
374
375 // Add arguments
376
377 #[cfg(cfail1)]
378 pub trait AddArgumentTrait {
379     fn method_name(&self);
380 }
381
382 #[cfg(cfail1)]
383 impl AddArgumentTrait for Foo {
384     fn method_name(&self) { }
385 }
386
387 #[cfg(not(cfail1))]
388 pub trait AddArgumentTrait {
389     fn method_name(&self, x: u32);
390 }
391
392 #[cfg(not(cfail1))]
393 #[rustc_clean(label="Hir", cfg="cfail2")]
394 #[rustc_clean(label="Hir", cfg="cfail3")]
395 #[rustc_metadata_dirty(cfg="cfail2")]
396 #[rustc_metadata_clean(cfg="cfail3")]
397 impl AddArgumentTrait for Foo {
398     #[rustc_dirty(label="Hir", cfg="cfail2")]
399     #[rustc_clean(label="Hir", cfg="cfail3")]
400     #[rustc_metadata_dirty(cfg="cfail2")]
401     #[rustc_metadata_clean(cfg="cfail3")]
402     fn method_name(&self, _x: u32) { }
403 }
404
405 // Change argument type
406
407 #[cfg(cfail1)]
408 pub trait ChangeArgumentTypeTrait {
409     fn method_name(&self, x: u32);
410 }
411
412 #[cfg(cfail1)]
413 impl ChangeArgumentTypeTrait for Foo {
414     fn method_name(&self, _x: u32) { }
415 }
416
417 #[cfg(not(cfail1))]
418 pub trait ChangeArgumentTypeTrait {
419     fn method_name(&self, x: char);
420 }
421
422 #[cfg(not(cfail1))]
423 #[rustc_clean(label="Hir", cfg="cfail2")]
424 #[rustc_clean(label="Hir", cfg="cfail3")]
425 #[rustc_metadata_dirty(cfg="cfail2")]
426 #[rustc_metadata_clean(cfg="cfail3")]
427 impl ChangeArgumentTypeTrait for Foo {
428     #[rustc_dirty(label="Hir", cfg="cfail2")]
429     #[rustc_clean(label="Hir", cfg="cfail3")]
430     #[rustc_metadata_dirty(cfg="cfail2")]
431     #[rustc_metadata_clean(cfg="cfail3")]
432     fn method_name(&self, _x: char) { }
433 }
434
435
436
437 struct Bar<T>(T);
438
439 // Add Type Parameter To Impl --------------------------------------------------
440 trait AddTypeParameterToImpl<T> {
441     fn id(t: T) -> T;
442 }
443
444 #[cfg(cfail1)]
445 impl AddTypeParameterToImpl<u32> for Bar<u32> {
446     fn id(t: u32) -> u32 { t }
447 }
448
449 #[cfg(not(cfail1))]
450 #[rustc_dirty(label="Hir", cfg="cfail2")]
451 #[rustc_clean(label="Hir", cfg="cfail3")]
452 #[rustc_metadata_dirty(cfg="cfail2")]
453 #[rustc_metadata_clean(cfg="cfail3")]
454 impl<T> AddTypeParameterToImpl<T> for Bar<T> {
455     #[rustc_dirty(label="Hir", cfg="cfail2")]
456     #[rustc_clean(label="Hir", cfg="cfail3")]
457     #[rustc_metadata_dirty(cfg="cfail2")]
458     #[rustc_metadata_clean(cfg="cfail3")]
459     fn id(t: T) -> T { t }
460 }
461
462
463
464 // Change Self Type of Impl ----------------------------------------------------
465 trait ChangeSelfTypeOfImpl {
466     fn id(self) -> Self;
467 }
468
469 #[cfg(cfail1)]
470 impl ChangeSelfTypeOfImpl for u32 {
471     fn id(self) -> Self { self }
472 }
473
474 #[cfg(not(cfail1))]
475 #[rustc_dirty(label="Hir", cfg="cfail2")]
476 #[rustc_clean(label="Hir", cfg="cfail3")]
477 #[rustc_metadata_dirty(cfg="cfail2")]
478 #[rustc_metadata_clean(cfg="cfail3")]
479 impl ChangeSelfTypeOfImpl for u64 {
480     #[rustc_clean(label="Hir", cfg="cfail2")]
481     #[rustc_clean(label="Hir", cfg="cfail3")]
482     #[rustc_metadata_dirty(cfg="cfail2")]
483     #[rustc_metadata_clean(cfg="cfail3")]
484     fn id(self) -> Self { self }
485 }
486
487
488
489 // Add Lifetime Bound to Impl --------------------------------------------------
490 trait AddLifetimeBoundToImplParameter {
491     fn id(self) -> Self;
492 }
493
494 #[cfg(cfail1)]
495 impl<T> AddLifetimeBoundToImplParameter for T {
496     fn id(self) -> Self { self }
497 }
498
499 #[cfg(not(cfail1))]
500 #[rustc_dirty(label="Hir", cfg="cfail2")]
501 #[rustc_clean(label="Hir", cfg="cfail3")]
502 #[rustc_metadata_dirty(cfg="cfail2")]
503 #[rustc_metadata_clean(cfg="cfail3")]
504 impl<T: 'static> AddLifetimeBoundToImplParameter for T {
505     #[rustc_clean(label="Hir", cfg="cfail2")]
506     #[rustc_clean(label="Hir", cfg="cfail3")]
507     #[rustc_metadata_dirty(cfg="cfail2")]
508     #[rustc_metadata_clean(cfg="cfail3")]
509     fn id(self) -> Self { self }
510 }
511
512
513
514 // Add Trait Bound to Impl Parameter -------------------------------------------
515 trait AddTraitBoundToImplParameter {
516     fn id(self) -> Self;
517 }
518
519 #[cfg(cfail1)]
520 impl<T> AddTraitBoundToImplParameter for T {
521     fn id(self) -> Self { self }
522 }
523
524 #[cfg(not(cfail1))]
525 #[rustc_dirty(label="Hir", cfg="cfail2")]
526 #[rustc_clean(label="Hir", cfg="cfail3")]
527 #[rustc_metadata_dirty(cfg="cfail2")]
528 #[rustc_metadata_clean(cfg="cfail3")]
529 impl<T: Clone> AddTraitBoundToImplParameter for T {
530     #[rustc_clean(label="Hir", cfg="cfail2")]
531     #[rustc_clean(label="Hir", cfg="cfail3")]
532     #[rustc_metadata_dirty(cfg="cfail2")]
533     #[rustc_metadata_clean(cfg="cfail3")]
534     fn id(self) -> Self { self }
535 }
536
537
538
539 // Add #[no_mangle] to Method --------------------------------------------------
540 trait AddNoMangleToMethod {
541     fn add_no_mangle_to_method(&self) { }
542 }
543
544 #[cfg(cfail1)]
545 impl AddNoMangleToMethod for Foo {
546     fn add_no_mangle_to_method(&self) { }
547 }
548
549 #[cfg(not(cfail1))]
550 #[rustc_clean(label="Hir", cfg="cfail2")]
551 #[rustc_clean(label="Hir", cfg="cfail3")]
552 #[rustc_metadata_clean(cfg="cfail2")]
553 #[rustc_metadata_clean(cfg="cfail3")]
554 impl AddNoMangleToMethod for Foo {
555     #[rustc_dirty(label="Hir", cfg="cfail2")]
556     #[rustc_clean(label="Hir", cfg="cfail3")]
557     #[rustc_metadata_dirty(cfg="cfail2")]
558     #[rustc_metadata_clean(cfg="cfail3")]
559     #[no_mangle]
560     fn add_no_mangle_to_method(&self) { }
561 }
562
563
564 // Make Method #[inline] -------------------------------------------------------
565 trait MakeMethodInline {
566     fn make_method_inline(&self) -> u8 { 0 }
567 }
568
569 #[cfg(cfail1)]
570 impl MakeMethodInline for Foo {
571     fn make_method_inline(&self) -> u8 { 0 }
572 }
573
574 #[cfg(not(cfail1))]
575 #[rustc_clean(label="Hir", cfg="cfail2")]
576 #[rustc_clean(label="Hir", cfg="cfail3")]
577 #[rustc_metadata_clean(cfg="cfail2")]
578 #[rustc_metadata_clean(cfg="cfail3")]
579 impl MakeMethodInline for Foo {
580     #[rustc_dirty(label="Hir", cfg="cfail2")]
581     #[rustc_clean(label="Hir", cfg="cfail3")]
582     #[rustc_metadata_dirty(cfg="cfail2")]
583     #[rustc_metadata_clean(cfg="cfail3")]
584     #[inline]
585     fn make_method_inline(&self) -> u8 { 0 }
586 }