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