]> git.proxmox.com Git - rustc.git/blob - src/test/incremental/hashes/if_expressions.rs
New upstream version 1.56.0~beta.4+dfsg1
[rustc.git] / src / test / incremental / hashes / if_expressions.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for if 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 // Change condition (if)
18 #[cfg(cfail1)]
19 pub fn change_condition(x: bool) -> u32 {
20 if x {
21 return 1
22 }
23
24 return 0
25 }
26
27 #[cfg(not(cfail1))]
28 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
29 #[rustc_clean(cfg="cfail3")]
30 pub fn change_condition(x: bool) -> u32 {
31 if !x {
32 return 1
33 }
34
35 return 0
36 }
37
38 // Change then branch (if)
39 #[cfg(cfail1)]
40 pub fn change_then_branch(x: bool) -> u32 {
41 if x {
42 return 1
43 }
44
45 return 0
46 }
47
48 #[cfg(not(cfail1))]
49 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
50 #[rustc_clean(cfg="cfail3")]
51 pub fn change_then_branch(x: bool) -> u32 {
52 if x {
53 return 2
54 }
55
56 return 0
57 }
58
59
60
61 // Change else branch (if)
62 #[cfg(cfail1)]
63 pub fn change_else_branch(x: bool) -> u32 {
64 if x {
65 1
66 } else {
67 2
68 }
69 }
70
71 #[cfg(not(cfail1))]
72 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
73 #[rustc_clean(cfg="cfail3")]
74 pub fn change_else_branch(x: bool) -> u32 {
75 if x {
76 1
77 } else {
78 3
79 }
80 }
81
82
83
84 // Add else branch (if)
85 #[cfg(cfail1)]
86 pub fn add_else_branch(x: bool) -> u32 {
87 let mut ret = 1;
88
89 if x {
90 ret = 2;
91 }
92
93 ret
94 }
95
96 #[cfg(not(cfail1))]
97 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck")]
98 #[rustc_clean(cfg="cfail3")]
99 pub fn add_else_branch(x: bool) -> u32 {
100 let mut ret = 1;
101
102 if x {
103 ret = 2;
104 } else {
105 }
106
107 ret
108 }
109
110
111
112 // Change condition (if let)
113 #[cfg(cfail1)]
114 pub fn change_condition_if_let(x: Option<u32>) -> u32 {
115 if let Some(_x) = x {
116 return 1
117 }
118
119 0
120 }
121
122 #[cfg(not(cfail1))]
123 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
124 #[rustc_clean(cfg="cfail3")]
125 pub fn change_condition_if_let(x: Option<u32>) -> u32 {
126 if let Some(_) = x {
127 return 1
128 }
129
130 0
131 }
132
133
134
135 // Change then branch (if let)
136 #[cfg(cfail1)]
137 pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
138 if let Some(x) = x {
139 return x
140 }
141
142 0
143 }
144
145 #[cfg(not(cfail1))]
146 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
147 #[rustc_clean(cfg="cfail3")]
148 pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
149 if let Some(x) = x {
150 return x + 1
151 }
152
153 0
154 }
155
156
157
158 // Change else branch (if let)
159 #[cfg(cfail1)]
160 pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
161 if let Some(x) = x {
162 x
163 } else {
164 1
165 }
166 }
167
168 #[cfg(not(cfail1))]
169 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
170 #[rustc_clean(cfg="cfail3")]
171 pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
172 if let Some(x) = x {
173 x
174 } else {
175 2
176 }
177 }
178
179
180
181 // Add else branch (if let)
182 #[cfg(cfail1)]
183 pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
184 let mut ret = 1;
185
186 if let Some(x) = x {
187 ret = x;
188 }
189
190 ret
191 }
192
193 #[cfg(not(cfail1))]
194 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck")]
195 #[rustc_clean(cfg="cfail3")]
196 pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
197 let mut ret = 1;
198
199 if let Some(x) = x {
200 ret = x;
201 } else {
202 }
203
204 ret
205 }