]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/trait_impls.rs
Auto merge of #38916 - estebank:pad-suggestion-list, 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_dirty(label="Hir", cfg="cfail2")]
50     #[rustc_clean(label="Hir", cfg="cfail3")]
51     #[rustc_metadata_dirty(cfg="cfail2")]
52     #[rustc_metadata_clean(cfg="cfail3")]
53     fn method_name2();
54 }
55
56 #[cfg(not(cfail1))]
57 #[rustc_dirty(label="Hir", cfg="cfail2")]
58 #[rustc_clean(label="Hir", cfg="cfail3")]
59 #[rustc_metadata_dirty(cfg="cfail2")]
60 #[rustc_metadata_clean(cfg="cfail3")]
61 impl ChangeMethodNameTrait for Foo {
62     #[rustc_dirty(label="Hir", cfg="cfail2")]
63     #[rustc_clean(label="Hir", cfg="cfail3")]
64     #[rustc_metadata_dirty(cfg="cfail2")]
65     #[rustc_metadata_clean(cfg="cfail3")]
66     fn method_name2() { }
67 }
68
69 // Change Method Body -----------------------------------------------------------
70 //
71 // This should affect the method itself, but not the trait.
72
73 pub trait ChangeMethodBodyTrait {
74     fn method_name();
75 }
76
77 #[cfg(cfail1)]
78 impl ChangeMethodBodyTrait for Foo {
79     fn method_name() { }
80 }
81
82 #[cfg(not(cfail1))]
83 #[rustc_clean(label="Hir", cfg="cfail2")]
84 #[rustc_clean(label="Hir", cfg="cfail3")]
85 #[rustc_metadata_clean(cfg="cfail2")]
86 #[rustc_metadata_clean(cfg="cfail3")]
87 impl ChangeMethodBodyTrait for Foo {
88     #[rustc_dirty(label="Hir", cfg="cfail2")]
89     #[rustc_clean(label="Hir", cfg="cfail3")]
90     #[rustc_metadata_dirty(cfg="cfail2")]
91     #[rustc_metadata_clean(cfg="cfail3")]
92     fn method_name() {
93         ()
94     }
95 }
96
97 // Change Method Selfness -----------------------------------------------------------
98
99 #[cfg(cfail1)]
100 pub trait ChangeMethodSelfnessTrait {
101     fn method_name();
102 }
103
104 #[cfg(cfail1)]
105 impl ChangeMethodSelfnessTrait for Foo {
106     fn method_name() { }
107 }
108
109 #[cfg(not(cfail1))]
110 pub trait ChangeMethodSelfnessTrait {
111     fn method_name(&self);
112 }
113
114 #[cfg(not(cfail1))]
115 #[rustc_dirty(label="Hir", cfg="cfail2")]
116 #[rustc_clean(label="Hir", cfg="cfail3")]
117 #[rustc_metadata_dirty(cfg="cfail2")]
118 #[rustc_metadata_clean(cfg="cfail3")]
119 impl ChangeMethodSelfnessTrait for Foo {
120     #[rustc_dirty(label="Hir", cfg="cfail2")]
121     #[rustc_clean(label="Hir", cfg="cfail3")]
122     #[rustc_metadata_dirty(cfg="cfail2")]
123     #[rustc_metadata_clean(cfg="cfail3")]
124     fn method_name(&self) {
125         ()
126     }
127 }
128
129 // Change Method Selfness -----------------------------------------------------------
130
131 #[cfg(cfail1)]
132 pub trait RemoveMethodSelfnessTrait {
133     fn method_name(&self);
134 }
135
136 #[cfg(cfail1)]
137 impl RemoveMethodSelfnessTrait for Foo {
138     fn method_name(&self) { }
139 }
140
141 #[cfg(not(cfail1))]
142 pub trait RemoveMethodSelfnessTrait {
143     fn method_name();
144 }
145
146 #[cfg(not(cfail1))]
147 #[rustc_dirty(label="Hir", cfg="cfail2")]
148 #[rustc_clean(label="Hir", cfg="cfail3")]
149 #[rustc_metadata_dirty(cfg="cfail2")]
150 #[rustc_metadata_clean(cfg="cfail3")]
151 impl RemoveMethodSelfnessTrait for Foo {
152     #[rustc_dirty(label="Hir", cfg="cfail2")]
153     #[rustc_clean(label="Hir", cfg="cfail3")]
154     #[rustc_metadata_dirty(cfg="cfail2")]
155     #[rustc_metadata_clean(cfg="cfail3")]
156     fn method_name() {
157         ()
158     }
159 }
160
161 // Change Method Selfmutness -----------------------------------------------------------
162
163 #[cfg(cfail1)]
164 pub trait ChangeMethodSelfmutnessTrait {
165     fn method_name(&self);
166 }
167
168 #[cfg(cfail1)]
169 impl ChangeMethodSelfmutnessTrait for Foo {
170     fn method_name(&self) { }
171 }
172
173 #[cfg(not(cfail1))]
174 pub trait ChangeMethodSelfmutnessTrait {
175     fn method_name(&mut self);
176 }
177
178 #[cfg(not(cfail1))]
179 #[rustc_clean(label="Hir", cfg="cfail2")]
180 #[rustc_clean(label="Hir", cfg="cfail3")]
181 #[rustc_metadata_dirty(cfg="cfail2")]
182 #[rustc_metadata_clean(cfg="cfail3")]
183 impl ChangeMethodSelfmutnessTrait for Foo {
184     #[rustc_dirty(label="Hir", cfg="cfail2")]
185     #[rustc_clean(label="Hir", cfg="cfail3")]
186     #[rustc_metadata_dirty(cfg="cfail2")]
187     #[rustc_metadata_clean(cfg="cfail3")]
188     fn method_name(&mut self) {
189         ()
190     }
191 }
192
193 // Change item kind -----------------------------------------------------------
194
195 #[cfg(cfail1)]
196 pub trait ChangeItemKindTrait {
197     fn name();
198 }
199
200 #[cfg(cfail1)]
201 impl ChangeItemKindTrait for Foo {
202     fn name() { }
203 }
204
205 #[cfg(not(cfail1))]
206 pub trait ChangeItemKindTrait {
207     type name;
208 }
209
210 #[cfg(not(cfail1))]
211 #[rustc_dirty(label="Hir", cfg="cfail2")]
212 #[rustc_clean(label="Hir", cfg="cfail3")]
213 #[rustc_metadata_dirty(cfg="cfail2")]
214 #[rustc_metadata_clean(cfg="cfail3")]
215 impl ChangeItemKindTrait for Foo {
216     type name = ();
217 }
218
219 // Remove item -----------------------------------------------------------
220
221 #[cfg(cfail1)]
222 pub trait RemoveItemTrait {
223     type TypeName;
224     fn method_name();
225 }
226
227 #[cfg(cfail1)]
228 impl RemoveItemTrait for Foo {
229     type TypeName = ();
230     fn method_name() { }
231 }
232
233 #[cfg(not(cfail1))]
234 pub trait RemoveItemTrait {
235     type TypeName;
236 }
237
238 #[cfg(not(cfail1))]
239 #[rustc_dirty(label="Hir", cfg="cfail2")]
240 #[rustc_clean(label="Hir", cfg="cfail3")]
241 #[rustc_metadata_dirty(cfg="cfail2")]
242 #[rustc_metadata_clean(cfg="cfail3")]
243 impl RemoveItemTrait for Foo {
244     type TypeName = ();
245 }
246
247 // Add item -----------------------------------------------------------
248
249 #[cfg(cfail1)]
250 pub trait AddItemTrait {
251     type TypeName;
252 }
253
254 #[cfg(cfail1)]
255 impl AddItemTrait for Foo {
256     type TypeName = ();
257 }
258
259 #[cfg(not(cfail1))]
260 pub trait AddItemTrait {
261     type TypeName;
262     fn method_name();
263 }
264
265 #[cfg(not(cfail1))]
266 #[rustc_dirty(label="Hir", cfg="cfail2")]
267 #[rustc_clean(label="Hir", cfg="cfail3")]
268 #[rustc_metadata_dirty(cfg="cfail2")]
269 #[rustc_metadata_clean(cfg="cfail3")]
270 impl AddItemTrait for Foo {
271     type TypeName = ();
272     fn method_name() { }
273 }
274
275 // Change has-value -----------------------------------------------------------
276
277 #[cfg(cfail1)]
278 pub trait ChangeHasValueTrait {
279     fn method_name();
280 }
281
282 #[cfg(cfail1)]
283 impl ChangeHasValueTrait for Foo {
284     fn method_name() { }
285 }
286
287 #[cfg(not(cfail1))]
288 #[rustc_dirty(label="Hir", cfg="cfail2")]
289 #[rustc_clean(label="Hir", cfg="cfail3")]
290 #[rustc_metadata_dirty(cfg="cfail2")]
291 #[rustc_metadata_clean(cfg="cfail3")]
292 pub trait ChangeHasValueTrait {
293     fn method_name() { }
294 }
295
296 #[cfg(not(cfail1))]
297 #[rustc_clean(label="Hir", cfg="cfail2")]
298 #[rustc_clean(label="Hir", cfg="cfail3")]
299 #[rustc_metadata_dirty(cfg="cfail2")]
300 #[rustc_metadata_clean(cfg="cfail3")]
301 impl ChangeHasValueTrait for Foo {
302     fn method_name() { }
303 }
304
305 // Add default
306
307 pub trait AddDefaultTrait {
308     fn method_name();
309 }
310
311 #[cfg(cfail1)]
312 impl AddDefaultTrait for Foo {
313     fn method_name() { }
314 }
315
316 #[cfg(not(cfail1))]
317 #[rustc_dirty(label="Hir", cfg="cfail2")]
318 #[rustc_clean(label="Hir", cfg="cfail3")]
319 #[rustc_metadata_dirty(cfg="cfail2")]
320 #[rustc_metadata_clean(cfg="cfail3")]
321 impl AddDefaultTrait for Foo {
322     default fn method_name() { }
323 }
324
325 // Remove default
326
327 pub trait RemoveDefaultTrait {
328     fn method_name();
329 }
330
331 #[cfg(cfail1)]
332 impl RemoveDefaultTrait for Foo {
333     default fn method_name() { }
334 }
335
336 #[cfg(not(cfail1))]
337 #[rustc_dirty(label="Hir", cfg="cfail2")]
338 #[rustc_clean(label="Hir", cfg="cfail3")]
339 #[rustc_metadata_dirty(cfg="cfail2")]
340 #[rustc_metadata_clean(cfg="cfail3")]
341 impl RemoveDefaultTrait for Foo {
342     fn method_name() { }
343 }
344
345 // Add arguments
346
347 #[cfg(cfail1)]
348 pub trait AddArgumentTrait {
349     fn method_name(&self);
350 }
351
352 #[cfg(cfail1)]
353 impl AddArgumentTrait for Foo {
354     fn method_name(&self) { }
355 }
356
357 #[cfg(not(cfail1))]
358 pub trait AddArgumentTrait {
359     fn method_name(&self, x: u32);
360 }
361
362 #[cfg(not(cfail1))]
363 #[rustc_clean(label="Hir", cfg="cfail2")]
364 #[rustc_clean(label="Hir", cfg="cfail3")]
365 #[rustc_metadata_dirty(cfg="cfail2")]
366 #[rustc_metadata_clean(cfg="cfail3")]
367 impl AddArgumentTrait for Foo {
368     #[rustc_dirty(label="Hir", cfg="cfail2")]
369     #[rustc_clean(label="Hir", cfg="cfail3")]
370     #[rustc_metadata_dirty(cfg="cfail2")]
371     #[rustc_metadata_clean(cfg="cfail3")]
372     fn method_name(&self, _x: u32) { }
373 }
374
375 // Change argument type
376
377 #[cfg(cfail1)]
378 pub trait ChangeArgumentTypeTrait {
379     fn method_name(&self, x: u32);
380 }
381
382 #[cfg(cfail1)]
383 impl ChangeArgumentTypeTrait for Foo {
384     fn method_name(&self, _x: u32) { }
385 }
386
387 #[cfg(not(cfail1))]
388 pub trait ChangeArgumentTypeTrait {
389     fn method_name(&self, x: char);
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 ChangeArgumentTypeTrait 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: char) { }
403 }
404
405
406
407 struct Bar<T>(T);
408
409 // Add Type Parameter To Impl --------------------------------------------------
410 trait AddTypeParameterToImpl<T> {
411     fn id(t: T) -> T;
412 }
413
414 #[cfg(cfail1)]
415 impl AddTypeParameterToImpl<u32> for Bar<u32> {
416     fn id(t: u32) -> u32 { t }
417 }
418
419 #[cfg(not(cfail1))]
420 #[rustc_dirty(label="Hir", cfg="cfail2")]
421 #[rustc_clean(label="Hir", cfg="cfail3")]
422 #[rustc_metadata_dirty(cfg="cfail2")]
423 #[rustc_metadata_clean(cfg="cfail3")]
424 impl<T> AddTypeParameterToImpl<T> for Bar<T> {
425     #[rustc_dirty(label="Hir", cfg="cfail2")]
426     #[rustc_clean(label="Hir", cfg="cfail3")]
427     #[rustc_metadata_dirty(cfg="cfail2")]
428     #[rustc_metadata_clean(cfg="cfail3")]
429     fn id(t: T) -> T { t }
430 }
431
432
433
434 // Change Self Type of Impl ----------------------------------------------------
435 trait ChangeSelfTypeOfImpl {
436     fn id(self) -> Self;
437 }
438
439 #[cfg(cfail1)]
440 impl ChangeSelfTypeOfImpl for u32 {
441     fn id(self) -> Self { self }
442 }
443
444 #[cfg(not(cfail1))]
445 #[rustc_dirty(label="Hir", cfg="cfail2")]
446 #[rustc_clean(label="Hir", cfg="cfail3")]
447 #[rustc_metadata_dirty(cfg="cfail2")]
448 #[rustc_metadata_clean(cfg="cfail3")]
449 impl ChangeSelfTypeOfImpl for u64 {
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     fn id(self) -> Self { self }
455 }
456
457
458
459 // Add Lifetime Bound to Impl --------------------------------------------------
460 trait AddLifetimeBoundToImplParameter {
461     fn id(self) -> Self;
462 }
463
464 #[cfg(cfail1)]
465 impl<T> AddLifetimeBoundToImplParameter for T {
466     fn id(self) -> Self { self }
467 }
468
469 #[cfg(not(cfail1))]
470 #[rustc_dirty(label="Hir", cfg="cfail2")]
471 #[rustc_clean(label="Hir", cfg="cfail3")]
472 #[rustc_metadata_dirty(cfg="cfail2")]
473 #[rustc_metadata_clean(cfg="cfail3")]
474 impl<T: 'static> AddLifetimeBoundToImplParameter for T {
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     fn id(self) -> Self { self }
480 }
481
482
483
484 // Add Trait Bound to Impl Parameter -------------------------------------------
485 trait AddTraitBoundToImplParameter {
486     fn id(self) -> Self;
487 }
488
489 #[cfg(cfail1)]
490 impl<T> AddTraitBoundToImplParameter for T {
491     fn id(self) -> Self { self }
492 }
493
494 #[cfg(not(cfail1))]
495 #[rustc_dirty(label="Hir", cfg="cfail2")]
496 #[rustc_clean(label="Hir", cfg="cfail3")]
497 #[rustc_metadata_dirty(cfg="cfail2")]
498 #[rustc_metadata_clean(cfg="cfail3")]
499 impl<T: Clone> AddTraitBoundToImplParameter for T {
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     fn id(self) -> Self { self }
505 }
506
507
508
509 // Add #[no_mangle] to Method --------------------------------------------------
510 trait AddNoMangleToMethod {
511     fn add_no_mangle_to_method(&self) { }
512 }
513
514 #[cfg(cfail1)]
515 impl AddNoMangleToMethod for Foo {
516     fn add_no_mangle_to_method(&self) { }
517 }
518
519 #[cfg(not(cfail1))]
520 #[rustc_clean(label="Hir", cfg="cfail2")]
521 #[rustc_clean(label="Hir", cfg="cfail3")]
522 #[rustc_metadata_clean(cfg="cfail2")]
523 #[rustc_metadata_clean(cfg="cfail3")]
524 impl AddNoMangleToMethod for Foo {
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     #[no_mangle]
530     fn add_no_mangle_to_method(&self) { }
531 }
532
533
534 // Make Method #[inline] -------------------------------------------------------
535 trait MakeMethodInline {
536     fn make_method_inline(&self) -> u8 { 0 }
537 }
538
539 #[cfg(cfail1)]
540 impl MakeMethodInline for Foo {
541     fn make_method_inline(&self) -> u8 { 0 }
542 }
543
544 #[cfg(not(cfail1))]
545 #[rustc_clean(label="Hir", cfg="cfail2")]
546 #[rustc_clean(label="Hir", cfg="cfail3")]
547 #[rustc_metadata_clean(cfg="cfail2")]
548 #[rustc_metadata_clean(cfg="cfail3")]
549 impl MakeMethodInline for Foo {
550     #[rustc_dirty(label="Hir", cfg="cfail2")]
551     #[rustc_clean(label="Hir", cfg="cfail3")]
552     #[rustc_metadata_dirty(cfg="cfail2")]
553     #[rustc_metadata_clean(cfg="cfail3")]
554     #[inline]
555     fn make_method_inline(&self) -> u8 { 0 }
556 }