]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/if_expressions.rs
ICH: Add test case for if- and if-let-expressions.
[rust.git] / src / test / incremental / hashes / if_expressions.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 // This test case tests the incremental compilation hash (ICH) implementation
13 // for if expressions.
14
15 // The general pattern followed here is: Change one thing between rev1 and rev2
16 // and make sure that the hash has changed, then change nothing between rev2 and
17 // rev3 and make sure that the hash has not changed.
18
19 // must-compile-successfully
20 // revisions: cfail1 cfail2 cfail3
21 // compile-flags: -Z query-dep-graph
22
23
24 #![allow(warnings)]
25 #![feature(rustc_attrs)]
26 #![crate_type="rlib"]
27
28 // Change condition (if) -------------------------------------------------------
29 #[cfg(cfail1)]
30 pub fn change_condition(x: bool) -> u32 {
31     if x {
32         return 1
33     }
34
35     return 0
36 }
37
38 #[cfg(not(cfail1))]
39 #[rustc_dirty(label="Hir", cfg="cfail2")]
40 #[rustc_clean(label="Hir", cfg="cfail3")]
41 #[rustc_metadata_dirty(cfg="cfail2")]
42 #[rustc_metadata_clean(cfg="cfail3")]
43 pub fn change_condition(x: bool) -> u32 {
44     if !x {
45         return 1
46     }
47
48     return 0
49 }
50
51 // Change then branch (if) -----------------------------------------------------
52 #[cfg(cfail1)]
53 pub fn change_then_branch(x: bool) -> u32 {
54     if x {
55         return 1
56     }
57
58     return 0
59 }
60
61 #[cfg(not(cfail1))]
62 #[rustc_dirty(label="Hir", cfg="cfail2")]
63 #[rustc_clean(label="Hir", cfg="cfail3")]
64 #[rustc_metadata_dirty(cfg="cfail2")]
65 #[rustc_metadata_clean(cfg="cfail3")]
66 pub fn change_then_branch(x: bool) -> u32 {
67     if x {
68         return 2
69     }
70
71     return 0
72 }
73
74
75
76 // Change else branch (if) -----------------------------------------------------
77 #[cfg(cfail1)]
78 pub fn change_else_branch(x: bool) -> u32 {
79     if x {
80         1
81     } else {
82         2
83     }
84 }
85
86 #[cfg(not(cfail1))]
87 #[rustc_dirty(label="Hir", cfg="cfail2")]
88 #[rustc_clean(label="Hir", cfg="cfail3")]
89 #[rustc_metadata_dirty(cfg="cfail2")]
90 #[rustc_metadata_clean(cfg="cfail3")]
91 pub fn change_else_branch(x: bool) -> u32 {
92     if x {
93         1
94     } else {
95         3
96     }
97 }
98
99
100
101 // Add else branch (if) --------------------------------------------------------
102 #[cfg(cfail1)]
103 pub fn add_else_branch(x: bool) -> u32 {
104     let mut ret = 1;
105
106     if x {
107         ret += 1;
108     }
109
110     ret
111 }
112
113 #[cfg(not(cfail1))]
114 #[rustc_dirty(label="Hir", cfg="cfail2")]
115 #[rustc_clean(label="Hir", cfg="cfail3")]
116 #[rustc_metadata_dirty(cfg="cfail2")]
117 #[rustc_metadata_clean(cfg="cfail3")]
118 pub fn add_else_branch(x: bool) -> u32 {
119     let mut ret = 1;
120
121     if x {
122         ret += 1;
123     } else {
124     }
125
126     ret
127 }
128
129
130
131 // Change condition (if let) ---------------------------------------------------
132 #[cfg(cfail1)]
133 pub fn change_condition_if_let(x: Option<u32>) -> u32 {
134     if let Some(_x) = x {
135         return 1
136     }
137
138     0
139 }
140
141 #[cfg(not(cfail1))]
142 #[rustc_dirty(label="Hir", cfg="cfail2")]
143 #[rustc_clean(label="Hir", cfg="cfail3")]
144 #[rustc_metadata_dirty(cfg="cfail2")]
145 #[rustc_metadata_clean(cfg="cfail3")]
146 pub fn change_condition_if_let(x: Option<u32>) -> u32 {
147     if let Some(_) = x {
148         return 1
149     }
150
151     0
152 }
153
154
155
156 // Change then branch (if let) -------------------------------------------------
157 #[cfg(cfail1)]
158 pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
159     if let Some(x) = x {
160         return x
161     }
162
163     0
164 }
165
166 #[cfg(not(cfail1))]
167 #[rustc_dirty(label="Hir", cfg="cfail2")]
168 #[rustc_clean(label="Hir", cfg="cfail3")]
169 #[rustc_metadata_dirty(cfg="cfail2")]
170 #[rustc_metadata_clean(cfg="cfail3")]
171 pub fn change_then_branch_if_let(x: Option<u32>) -> u32 {
172     if let Some(x) = x {
173         return x + 1
174     }
175
176     0
177 }
178
179
180
181 // Change else branch (if let) -------------------------------------------------
182 #[cfg(cfail1)]
183 pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
184     if let Some(x) = x {
185         x
186     } else {
187         1
188     }
189 }
190
191 #[cfg(not(cfail1))]
192 #[rustc_dirty(label="Hir", cfg="cfail2")]
193 #[rustc_clean(label="Hir", cfg="cfail3")]
194 #[rustc_metadata_dirty(cfg="cfail2")]
195 #[rustc_metadata_clean(cfg="cfail3")]
196 pub fn change_else_branch_if_let(x: Option<u32>) -> u32 {
197     if let Some(x) = x {
198         x
199     } else {
200         2
201     }
202 }
203
204
205
206 // Add else branch (if let) ----------------------------------------------------
207 #[cfg(cfail1)]
208 pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
209     let mut ret = 1;
210
211     if let Some(x) = x {
212         ret += x;
213     }
214
215     ret
216 }
217
218 #[cfg(not(cfail1))]
219 #[rustc_dirty(label="Hir", cfg="cfail2")]
220 #[rustc_clean(label="Hir", cfg="cfail3")]
221 #[rustc_metadata_dirty(cfg="cfail2")]
222 #[rustc_metadata_clean(cfg="cfail3")]
223 pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
224     let mut ret = 1;
225
226     if let Some(x) = x {
227         ret += x;
228     } else {
229     }
230
231     ret
232 }