]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/if_expressions.rs
Rollup merge of #100022 - joboet:faster_threadid, r=joshtriplett
[rust.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 cfail4 cfail5 cfail6
10 // compile-flags: -Z query-dep-graph -O
11 // [cfail1]compile-flags: -Zincremental-ignore-spans
12 // [cfail2]compile-flags: -Zincremental-ignore-spans
13 // [cfail3]compile-flags: -Zincremental-ignore-spans
14 // [cfail4]compile-flags: -Zincremental-relative-spans
15 // [cfail5]compile-flags: -Zincremental-relative-spans
16 // [cfail6]compile-flags: -Zincremental-relative-spans
17
18 #![allow(warnings)]
19 #![feature(rustc_attrs)]
20 #![crate_type="rlib"]
21
22 // Change condition (if)
23 #[cfg(any(cfail1,cfail4))]
24 pub fn change_condition(x: bool) -> u32 {
25     if  x {
26         return 1
27     }
28
29     return 0
30 }
31
32 #[cfg(not(any(cfail1,cfail4)))]
33 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
34 #[rustc_clean(cfg="cfail3")]
35 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
36 #[rustc_clean(cfg="cfail6")]
37 pub fn change_condition(x: bool) -> u32 {
38     if !x {
39         return 1
40     }
41
42     return 0
43 }
44
45 // Change then branch (if)
46 #[cfg(any(cfail1,cfail4))]
47 pub fn change_then_branch(x: bool) -> u32 {
48     if x {
49         return 1
50     }
51
52     return 0
53 }
54
55 #[cfg(not(any(cfail1,cfail4)))]
56 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
57 #[rustc_clean(cfg="cfail3")]
58 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
59 #[rustc_clean(cfg="cfail6")]
60 pub fn change_then_branch(x: bool) -> u32 {
61     if x {
62         return 2
63     }
64
65     return 0
66 }
67
68
69
70 // Change else branch (if)
71 #[cfg(any(cfail1,cfail4))]
72 pub fn change_else_branch(x: bool) -> u32 {
73     if x {
74         1
75     } else {
76         2
77     }
78 }
79
80 #[cfg(not(any(cfail1,cfail4)))]
81 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
82 #[rustc_clean(cfg="cfail3")]
83 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
84 #[rustc_clean(cfg="cfail6")]
85 pub fn change_else_branch(x: bool) -> u32 {
86     if x {
87         1
88     } else {
89         3
90     }
91 }
92
93
94
95 // Add else branch (if)
96 #[cfg(any(cfail1,cfail4))]
97 pub fn add_else_branch(x: bool) -> u32 {
98     let mut ret = 1;
99
100     if x {
101         ret = 2;
102     /*----*/
103     }
104
105     ret
106 }
107
108 #[cfg(not(any(cfail1,cfail4)))]
109 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,typeck")]
110 #[rustc_clean(cfg="cfail3")]
111 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,typeck")]
112 #[rustc_clean(cfg="cfail6")]
113 pub fn add_else_branch(x: bool) -> u32 {
114     let mut ret = 1;
115
116     if x {
117         ret = 2;
118     } else {
119     }
120
121     ret
122 }
123
124
125
126 // Change condition (if let)
127 #[cfg(any(cfail1,cfail4))]
128 pub fn change_condition_if_let(x: Option<u32>) -> u32 {
129     if let Some(_x) = x {
130         return 1
131     }
132
133     0
134 }
135
136 #[cfg(not(any(cfail1,cfail4)))]
137 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
138 #[rustc_clean(cfg="cfail3")]
139 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
140 #[rustc_clean(cfg="cfail6")]
141 pub fn change_condition_if_let(x: Option<u32>) -> u32 {
142     if let Some(_ ) = x {
143         return 1
144     }
145
146     0
147 }
148
149
150
151 // Change then branch (if let)
152 #[cfg(any(cfail1,cfail4))]
153 pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
154     if let Some(x) = x {
155         return x //-
156     }
157
158     0
159 }
160
161 #[cfg(not(any(cfail1,cfail4)))]
162 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
163 #[rustc_clean(cfg="cfail3")]
164 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,optimized_mir,typeck")]
165 #[rustc_clean(cfg="cfail6")]
166 pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
167     if let Some(x) = x {
168         return x + 1
169     }
170
171     0
172 }
173
174
175
176 // Change else branch (if let)
177 #[cfg(any(cfail1,cfail4))]
178 pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
179     if let Some(x) = x {
180         x
181     } else {
182         1
183     }
184 }
185
186 #[cfg(not(any(cfail1,cfail4)))]
187 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")]
188 #[rustc_clean(cfg="cfail3")]
189 #[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
190 #[rustc_clean(cfg="cfail6")]
191 pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
192     if let Some(x) = x {
193         x
194     } else {
195         2
196     }
197 }
198
199
200
201 // Add else branch (if let)
202 #[cfg(any(cfail1,cfail4))]
203 pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
204     let mut ret = 1;
205
206     if let Some(x) = x {
207         ret = x;
208     /*----*/
209     }
210
211     ret
212 }
213
214 #[cfg(not(any(cfail1,cfail4)))]
215 #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,typeck")]
216 #[rustc_clean(cfg="cfail3")]
217 #[rustc_clean(cfg="cfail5", except="hir_owner,hir_owner_nodes,typeck,optimized_mir")]
218 #[rustc_clean(cfg="cfail6")]
219 pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
220     let mut ret = 1;
221
222     if let Some(x) = x {
223         ret = x;
224     } else {
225     }
226
227     ret
228 }