]> git.proxmox.com Git - rustc.git/blob - src/test/incremental/hashes/inherent_impls.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / test / incremental / hashes / inherent_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
10 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
11
12
13 #![allow(warnings)]
14 #![feature(rustc_attrs)]
15 #![crate_type="rlib"]
16
17 pub struct Foo;
18
19 // Change Method Name -----------------------------------------------------------
20 #[cfg(cfail1)]
21 impl Foo {
22 pub fn method_name() { }
23 }
24
25 #[cfg(not(cfail1))]
26 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,associated_item_def_ids")]
27 #[rustc_clean(cfg="cfail3")]
28 impl Foo {
29 #[rustc_clean(cfg="cfail3")]
30 pub fn method_name2() { }
31 }
32
33 // Change Method Body -----------------------------------------------------------
34 //
35 // This should affect the method itself, but not the impl.
36 #[cfg(cfail1)]
37 impl Foo {
38 pub fn method_body() { }
39 }
40
41 #[cfg(not(cfail1))]
42 #[rustc_clean(cfg="cfail2")]
43 #[rustc_clean(cfg="cfail3")]
44 impl Foo {
45 #[rustc_clean(
46 cfg="cfail2",
47 except="hir_owner_nodes,optimized_mir,promoted_mir,mir_built,typeck_tables_of"
48 )]
49 #[rustc_clean(cfg="cfail3")]
50 pub fn method_body() {
51 println!("Hello, world!");
52 }
53 }
54
55
56 // Change Method Body (inlined) ------------------------------------------------
57 //
58 // This should affect the method itself, but not the impl.
59 #[cfg(cfail1)]
60 impl Foo {
61 #[inline]
62 pub fn method_body_inlined() { }
63 }
64
65 #[cfg(not(cfail1))]
66 #[rustc_clean(cfg="cfail2")]
67 #[rustc_clean(cfg="cfail3")]
68 impl Foo {
69 #[rustc_clean(
70 cfg="cfail2",
71 except="hir_owner_nodes,optimized_mir,promoted_mir,mir_built,typeck_tables_of"
72 )]
73 #[rustc_clean(cfg="cfail3")]
74 #[inline]
75 pub fn method_body_inlined() {
76 println!("Hello, world!");
77 }
78 }
79
80
81 // Change Method Privacy -------------------------------------------------------
82 #[cfg(cfail1)]
83 impl Foo {
84 pub fn method_privacy() { }
85 }
86
87 #[cfg(not(cfail1))]
88 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
89 #[rustc_clean(cfg="cfail3")]
90 impl Foo {
91 #[rustc_clean(cfg="cfail2", except="associated_item,hir_owner,hir_owner_nodes")]
92 #[rustc_clean(cfg="cfail3")]
93 fn method_privacy() { }
94 }
95
96 // Change Method Selfness -----------------------------------------------------------
97 #[cfg(cfail1)]
98 impl Foo {
99 pub fn method_selfness() { }
100 }
101
102 #[cfg(not(cfail1))]
103 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
104 #[rustc_clean(cfg="cfail3")]
105 impl Foo {
106 #[rustc_dirty(cfg="cfail2", except="type_of,predicates_of,promoted_mir")]
107 #[rustc_clean(cfg="cfail3")]
108 pub fn method_selfness(&self) { }
109 }
110
111 // Change Method Selfmutness ---------------------------------------------------
112 #[cfg(cfail1)]
113 impl Foo {
114 pub fn method_selfmutness(&self) { }
115 }
116
117 #[cfg(not(cfail1))]
118 #[rustc_clean(cfg="cfail2")]
119 #[rustc_clean(cfg="cfail3")]
120 impl Foo {
121 #[rustc_clean(
122 cfg="cfail2",
123 except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir,mir_built"
124 )]
125 #[rustc_clean(cfg="cfail3")]
126 pub fn method_selfmutness(&mut self) { }
127 }
128
129
130
131 // Add Method To Impl ----------------------------------------------------------
132 #[cfg(cfail1)]
133 impl Foo {
134 pub fn add_method_to_impl1(&self) { }
135 }
136
137 #[cfg(not(cfail1))]
138 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,associated_item_def_ids")]
139 #[rustc_clean(cfg="cfail3")]
140 impl Foo {
141 #[rustc_clean(cfg="cfail2")]
142 #[rustc_clean(cfg="cfail3")]
143 pub fn add_method_to_impl1(&self) { }
144
145 #[rustc_clean(cfg="cfail3")]
146 pub fn add_method_to_impl2(&self) { }
147 }
148
149
150
151 // Add Method Parameter --------------------------------------------------------
152 #[cfg(cfail1)]
153 impl Foo {
154 pub fn add_method_parameter(&self) { }
155 }
156
157 #[cfg(not(cfail1))]
158 #[rustc_clean(cfg="cfail2")]
159 #[rustc_clean(cfg="cfail3")]
160 impl Foo {
161 #[rustc_clean(
162 cfg="cfail2",
163 except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir,mir_built"
164 )]
165 #[rustc_clean(cfg="cfail3")]
166 pub fn add_method_parameter(&self, _: i32) { }
167 }
168
169
170
171 // Change Method Parameter Name ------------------------------------------------
172 #[cfg(cfail1)]
173 impl Foo {
174 pub fn change_method_parameter_name(&self, a: i64) { }
175 }
176
177 #[cfg(not(cfail1))]
178 #[rustc_clean(cfg="cfail2")]
179 #[rustc_clean(cfg="cfail3")]
180 impl Foo {
181 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")]
182 #[rustc_clean(cfg="cfail3")]
183 pub fn change_method_parameter_name(&self, b: i64) { }
184 }
185
186
187
188 // Change Method Return Type ---------------------------------------------------
189 #[cfg(cfail1)]
190 impl Foo {
191 pub fn change_method_return_type(&self) -> u16 { 0 }
192 }
193
194 #[cfg(not(cfail1))]
195 #[rustc_clean(cfg="cfail2")]
196 #[rustc_clean(cfg="cfail3")]
197 impl Foo {
198 #[rustc_clean(
199 cfg="cfail2",
200 except="hir_owner,hir_owner_nodes,fn_sig,optimized_mir,mir_built,typeck_tables_of")]
201 #[rustc_clean(cfg="cfail3")]
202 pub fn change_method_return_type(&self) -> u8 { 0 }
203 }
204
205
206
207 // Make Method #[inline] -------------------------------------------------------
208 #[cfg(cfail1)]
209 impl Foo {
210 pub fn make_method_inline(&self) -> u8 { 0 }
211 }
212
213 #[cfg(not(cfail1))]
214 #[rustc_clean(cfg="cfail2")]
215 #[rustc_clean(cfg="cfail3")]
216 impl Foo {
217 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
218 #[rustc_clean(cfg="cfail3")]
219 #[inline]
220 pub fn make_method_inline(&self) -> u8 { 0 }
221 }
222
223
224
225 // Change order of parameters -------------------------------------------------
226 #[cfg(cfail1)]
227 impl Foo {
228 pub fn change_method_parameter_order(&self, a: i64, b: i64) { }
229 }
230
231 #[cfg(not(cfail1))]
232 #[rustc_clean(cfg="cfail2")]
233 #[rustc_clean(cfg="cfail3")]
234 impl Foo {
235 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")]
236 #[rustc_clean(cfg="cfail3")]
237 pub fn change_method_parameter_order(&self, b: i64, a: i64) { }
238 }
239
240
241
242 // Make method unsafe ----------------------------------------------------------
243 #[cfg(cfail1)]
244 impl Foo {
245 pub fn make_method_unsafe(&self) { }
246 }
247
248 #[cfg(not(cfail1))]
249 #[rustc_clean(cfg="cfail2")]
250 #[rustc_clean(cfg="cfail3")]
251 impl Foo {
252 #[rustc_clean(
253 cfg="cfail2",
254 except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir,mir_built"
255 )]
256 #[rustc_clean(cfg="cfail3")]
257 pub unsafe fn make_method_unsafe(&self) { }
258 }
259
260
261
262 // Make method extern ----------------------------------------------------------
263 #[cfg(cfail1)]
264 impl Foo {
265 pub fn make_method_extern(&self) { }
266 }
267
268 #[cfg(not(cfail1))]
269 #[rustc_clean(cfg="cfail2")]
270 #[rustc_clean(cfg="cfail3")]
271 impl Foo {
272 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of")]
273 #[rustc_clean(cfg="cfail3")]
274 pub extern fn make_method_extern(&self) { }
275 }
276
277
278
279 // Change method calling convention --------------------------------------------
280 #[cfg(cfail1)]
281 impl Foo {
282 pub extern "C" fn change_method_calling_convention(&self) { }
283 }
284
285 #[cfg(not(cfail1))]
286 #[rustc_clean(cfg="cfail2")]
287 #[rustc_clean(cfg="cfail3")]
288 impl Foo {
289 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of")]
290 #[rustc_clean(cfg="cfail3")]
291 pub extern "system" fn change_method_calling_convention(&self) { }
292 }
293
294
295
296 // Add Lifetime Parameter to Method --------------------------------------------
297 #[cfg(cfail1)]
298 impl Foo {
299 pub fn add_lifetime_parameter_to_method(&self) { }
300 }
301
302 #[cfg(not(cfail1))]
303 #[rustc_clean(cfg="cfail2")]
304 #[rustc_clean(cfg="cfail3")]
305 impl Foo {
306 // Warning: Note that `typeck_tables_of` are coming up clean here.
307 // The addition or removal of lifetime parameters that don't
308 // appear in the arguments or fn body in any way does not, in
309 // fact, affect the `typeck_tables_of` in any semantic way (at least
310 // as of this writing). **However,** altering the order of
311 // lowering **can** cause it appear to affect the `typeck_tables_of`:
312 // if we lower generics before the body, then the `HirId` for
313 // things in the body will be affected. So if you start to see
314 // `typeck_tables_of` appear dirty, that might be the cause. -nmatsakis
315 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
316 #[rustc_clean(cfg="cfail3")]
317 pub fn add_lifetime_parameter_to_method<'a>(&self) { }
318 }
319
320
321
322 // Add Type Parameter To Method ------------------------------------------------
323 #[cfg(cfail1)]
324 impl Foo {
325 pub fn add_type_parameter_to_method(&self) { }
326 }
327
328 #[cfg(not(cfail1))]
329 #[rustc_clean(cfg="cfail2")]
330 #[rustc_clean(cfg="cfail3")]
331 impl Foo {
332 // Warning: Note that `typeck_tables_of` are coming up clean here.
333 // The addition or removal of type parameters that don't appear in
334 // the arguments or fn body in any way does not, in fact, affect
335 // the `typeck_tables_of` in any semantic way (at least as of this
336 // writing). **However,** altering the order of lowering **can**
337 // cause it appear to affect the `typeck_tables_of`: if we lower
338 // generics before the body, then the `HirId` for things in the
339 // body will be affected. So if you start to see `typeck_tables_of`
340 // appear dirty, that might be the cause. -nmatsakis
341 #[rustc_clean(
342 cfg="cfail2",
343 except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of",
344 )]
345 #[rustc_clean(cfg="cfail3")]
346 pub fn add_type_parameter_to_method<T>(&self) { }
347 }
348
349
350
351 // Add Lifetime Bound to Lifetime Parameter of Method --------------------------
352 #[cfg(cfail1)]
353 impl Foo {
354 pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b>(&self) { }
355 }
356
357 #[cfg(not(cfail1))]
358 #[rustc_clean(cfg="cfail2")]
359 #[rustc_clean(cfg="cfail3")]
360 impl Foo {
361 #[rustc_clean(
362 cfg="cfail2",
363 except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of"
364 )]
365 #[rustc_clean(cfg="cfail3")]
366 pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { }
367 }
368
369
370
371 // Add Lifetime Bound to Type Parameter of Method ------------------------------
372 #[cfg(cfail1)]
373 impl Foo {
374 pub fn add_lifetime_bound_to_type_param_of_method<'a, T>(&self) { }
375 }
376
377 #[cfg(not(cfail1))]
378 #[rustc_clean(cfg="cfail2")]
379 #[rustc_clean(cfg="cfail3")]
380 impl Foo {
381 // Warning: Note that `typeck_tables_of` are coming up clean here.
382 // The addition or removal of bounds that don't appear in the
383 // arguments or fn body in any way does not, in fact, affect the
384 // `typeck_tables_of` in any semantic way (at least as of this
385 // writing). **However,** altering the order of lowering **can**
386 // cause it appear to affect the `typeck_tables_of`: if we lower
387 // generics before the body, then the `HirId` for things in the
388 // body will be affected. So if you start to see `typeck_tables_of`
389 // appear dirty, that might be the cause. -nmatsakis
390 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of,\
391 type_of")]
392 #[rustc_clean(cfg="cfail3")]
393 pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { }
394 }
395
396
397
398 // Add Trait Bound to Type Parameter of Method ------------------------------
399 #[cfg(cfail1)]
400 impl Foo {
401 pub fn add_trait_bound_to_type_param_of_method<T>(&self) { }
402 }
403
404 #[cfg(not(cfail1))]
405 #[rustc_clean(cfg="cfail2")]
406 #[rustc_clean(cfg="cfail3")]
407 impl Foo {
408 // Warning: Note that `typeck_tables_of` are coming up clean here.
409 // The addition or removal of bounds that don't appear in the
410 // arguments or fn body in any way does not, in fact, affect the
411 // `typeck_tables_of` in any semantic way (at least as of this
412 // writing). **However,** altering the order of lowering **can**
413 // cause it appear to affect the `typeck_tables_of`: if we lower
414 // generics before the body, then the `HirId` for things in the
415 // body will be affected. So if you start to see `typeck_tables_of`
416 // appear dirty, that might be the cause. -nmatsakis
417 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,predicates_of")]
418 #[rustc_clean(cfg="cfail3")]
419 pub fn add_trait_bound_to_type_param_of_method<T: Clone>(&self) { }
420 }
421
422
423
424 // Add #[no_mangle] to Method --------------------------------------------------
425 #[cfg(cfail1)]
426 impl Foo {
427 pub fn add_no_mangle_to_method(&self) { }
428 }
429
430 #[cfg(not(cfail1))]
431 #[rustc_clean(cfg="cfail2")]
432 #[rustc_clean(cfg="cfail3")]
433 impl Foo {
434 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
435 #[rustc_clean(cfg="cfail3")]
436 #[no_mangle]
437 pub fn add_no_mangle_to_method(&self) { }
438 }
439
440
441
442 struct Bar<T>(T);
443
444 // Add Type Parameter To Impl --------------------------------------------------
445 #[cfg(cfail1)]
446 impl Bar<u32> {
447 pub fn add_type_parameter_to_impl(&self) { }
448 }
449
450 #[cfg(not(cfail1))]
451 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of")]
452 #[rustc_clean(cfg="cfail3")]
453 impl<T> Bar<T> {
454 #[rustc_clean(
455 cfg="cfail2",
456 except="generics_of,fn_sig,typeck_tables_of,type_of,optimized_mir,mir_built"
457 )]
458 #[rustc_clean(cfg="cfail3")]
459 pub fn add_type_parameter_to_impl(&self) { }
460 }
461
462
463
464 // Change Self Type of Impl ----------------------------------------------------
465 #[cfg(cfail1)]
466 impl Bar<u32> {
467 pub fn change_impl_self_type(&self) { }
468 }
469
470 #[cfg(not(cfail1))]
471 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
472 #[rustc_clean(cfg="cfail3")]
473 impl Bar<u64> {
474 #[rustc_clean(cfg="cfail2", except="fn_sig,optimized_mir,mir_built,typeck_tables_of")]
475 #[rustc_clean(cfg="cfail3")]
476 pub fn change_impl_self_type(&self) { }
477 }
478
479
480
481 // Add Lifetime Bound to Impl --------------------------------------------------
482 #[cfg(cfail1)]
483 impl<T> Bar<T> {
484 pub fn add_lifetime_bound_to_impl_parameter(&self) { }
485 }
486
487 #[cfg(not(cfail1))]
488 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
489 #[rustc_clean(cfg="cfail3")]
490 impl<T: 'static> Bar<T> {
491 #[rustc_clean(cfg="cfail2")]
492 #[rustc_clean(cfg="cfail3")]
493 pub fn add_lifetime_bound_to_impl_parameter(&self) { }
494 }
495
496
497
498 // Add Trait Bound to Impl Parameter -------------------------------------------
499 #[cfg(cfail1)]
500 impl<T> Bar<T> {
501 pub fn add_trait_bound_to_impl_parameter(&self) { }
502 }
503
504 #[cfg(not(cfail1))]
505 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")]
506 #[rustc_clean(cfg="cfail3")]
507 impl<T: Clone> Bar<T> {
508 #[rustc_clean(cfg="cfail2")]
509 #[rustc_clean(cfg="cfail3")]
510 pub fn add_trait_bound_to_impl_parameter(&self) { }
511 }
512
513
514 // Force instantiation of some fns so we can check their hash.
515 pub fn instantiation_root() {
516 Foo::method_privacy();
517
518 #[cfg(cfail1)]
519 {
520 Bar(0u32).change_impl_self_type();
521 }
522
523 #[cfg(not(cfail1))]
524 {
525 Bar(0u64).change_impl_self_type();
526 }
527 }