]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/closure_expressions.rs
Improve some compiletest documentation
[rust.git] / src / test / incremental / hashes / closure_expressions.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for closure expression.
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 // compile-pass
9 // revisions: cfail1 cfail2 cfail3
10 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
11
12 #![allow(warnings)]
13 #![feature(rustc_attrs)]
14 #![crate_type="rlib"]
15
16
17 // Change closure body ---------------------------------------------------------
18 #[cfg(cfail1)]
19 pub fn change_closure_body() {
20     let _ = || 1u32;
21 }
22
23 #[cfg(not(cfail1))]
24 #[rustc_clean(cfg="cfail2", except="HirBody")]
25 #[rustc_clean(cfg="cfail3")]
26 pub fn change_closure_body() {
27     let _ = || 3u32;
28 }
29
30
31
32 // Add parameter ---------------------------------------------------------------
33 #[cfg(cfail1)]
34 pub fn add_parameter() {
35     let x = 0u32;
36     let _ = || x + 1;
37 }
38
39 #[cfg(not(cfail1))]
40 #[rustc_clean(cfg="cfail2", except="HirBody, MirBuilt, MirOptimized, TypeckTables")]
41 #[rustc_clean(cfg="cfail3")]
42 pub fn add_parameter() {
43     let x = 0u32;
44     let _ = |x: u32| x + 1;
45 }
46
47
48
49 // Change parameter pattern ----------------------------------------------------
50 #[cfg(cfail1)]
51 pub fn change_parameter_pattern() {
52     let _ = |x: &u32| x;
53 }
54
55 #[cfg(not(cfail1))]
56 #[rustc_clean(cfg="cfail2", except="HirBody, MirBuilt, TypeckTables")]
57 #[rustc_clean(cfg="cfail3")]
58 pub fn change_parameter_pattern() {
59     let _ = |&x: &u32| x;
60 }
61
62
63
64 // Add `move` to closure -------------------------------------------------------
65 #[cfg(cfail1)]
66 pub fn add_move() {
67     let _ = || 1;
68 }
69
70 #[cfg(not(cfail1))]
71 #[rustc_clean(cfg="cfail2", except="HirBody")]
72 #[rustc_clean(cfg="cfail3")]
73 pub fn add_move() {
74     let _ = move || 1;
75 }
76
77
78
79 // Add type ascription to parameter --------------------------------------------
80 #[cfg(cfail1)]
81 pub fn add_type_ascription_to_parameter() {
82     let closure = |x| x + 1u32;
83     let _: u32 = closure(1);
84 }
85
86 #[cfg(not(cfail1))]
87 #[rustc_clean(cfg="cfail2", except="HirBody, MirBuilt, TypeckTables")]
88 #[rustc_clean(cfg="cfail3")]
89 pub fn add_type_ascription_to_parameter() {
90     let closure = |x: u32| x + 1u32;
91     let _: u32 = closure(1);
92 }
93
94
95
96 // Change parameter type -------------------------------------------------------
97 #[cfg(cfail1)]
98 pub fn change_parameter_type() {
99     let closure = |x: u32| (x as u64) + 1;
100     let _ = closure(1);
101 }
102
103 #[cfg(not(cfail1))]
104 #[rustc_clean(cfg="cfail2", except="HirBody, MirBuilt, MirOptimized, TypeckTables")]
105 #[rustc_clean(cfg="cfail3")]
106 pub fn change_parameter_type() {
107     let closure = |x: u16| (x as u64) + 1;
108     let _ = closure(1);
109 }