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