1 #![feature(plugin, inclusive_range_syntax)]
2 #![feature(dotdot_in_tuple_patterns)]
5 #![allow(dead_code, no_effect, unnecessary_operation)]
6 #![allow(let_and_return)]
7 #![allow(needless_return)]
8 #![allow(unused_variables)]
9 #![allow(cyclomatic_complexity)]
10 #![allow(blacklisted_name)]
11 #![allow(collapsible_if)]
12 #![allow(zero_divided_by_zero, eq_op)]
15 fn foo() -> bool { unimplemented!() }
21 #[deny(if_same_then_else)]
22 #[deny(match_same_arms)]
23 fn if_same_then_else() -> Result<&'static str, ()> {
34 else { //~ERROR this `if` has identical blocks
71 else { //~ERROR this `if` has identical blocks
84 else { //~ERROR this `if` has identical blocks
97 while foo() { break; }
100 else { //~ERROR this `if` has identical blocks
108 while foo() { break; }
113 //~^NOTE same as this
124 else if foo() { //~ERROR this `if` has identical blocks
134 //~^NOTE same as this
135 if let Some(a) = Some(42) {}
137 else { //~ERROR this `if` has identical blocks
138 if let Some(a) = Some(42) {}
142 //~^NOTE same as this
143 if let (1, .., 3) = (1, 2, 3) {}
145 else { //~ERROR this `if` has identical blocks
146 if let (1, .., 3) = (1, 2, 3) {}
150 if let (1, .., 3) = (1, 2, 3) {}
153 if let (.., 3) = (1, 2, 3) {}
157 if let (1, .., 3) = (1, 2, 3) {}
160 if let (.., 4) = (1, 2, 3) {}
164 if let (1, .., 3) = (1, 2, 3) {}
167 if let (.., 1, 3) = (1, 2, 3) {}
171 if let Some(a) = Some(42) {}
174 if let Some(a) = Some(43) {}
179 //~^NOTE same as this
181 51 => foo(), //~ERROR this `match` has identical arm bodies
185 let _ = match Some(42) {
187 //~^NOTE same as this
188 //~|NOTE `Some(_) | None`
189 None => 24, //~ERROR this `match` has identical arm bodies
192 let _ = match Some(42) {
197 let _ = match Some(42) {
199 Some(a) => 24, // bindings are different
203 let _ = match Some(42) {
204 Some(a) if a > 0 => 24,
205 Some(a) => 24, // one arm has a guard
209 match (Some(42), Some(42)) {
210 (Some(a), None) => bar(a),
211 //~^NOTE same as this
212 //~|NOTE `(Some(a), None) | (None, Some(a))`
213 (None, Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
217 match (Some(42), Some(42)) {
218 (Some(a), ..) => bar(a),
219 //~^NOTE same as this
220 //~|NOTE `(Some(a), ..) | (.., Some(a))`
221 (.., Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
227 //~^NOTE same as this
228 //~|NOTE `(1, .., 3) | (.., 3)`
229 (.., 3) => 42, //~ERROR this `match` has identical arm bodies
234 //~^NOTE same as this
236 } else { //~ERROR this `if` has identical blocks
241 //~^NOTE same as this
243 } else { //~ERROR this `if` has identical blocks
262 //~^NOTE same as this
264 } else { //~ERROR this `if` has identical blocks
268 let _ = match Some(()) {
273 match (Some(42), Some("")) {
274 (Some(a), None) => bar(a),
275 (None, Some(a)) => bar(a), // bindings have different types
280 //~^NOTE same as this
283 else { //~ERROR this `if` has identical blocks
288 //~^NOTE same as this
290 return Ok(&foo[0..]);
294 return Ok(&foo[0..]);
296 else { //~ERROR this `if` has identical blocks
298 return Ok(&foo[0..]);
302 #[deny(ifs_same_cond)]
303 #[allow(if_same_then_else)] // all empty blocks
309 //~^NOTE same as this
311 else if b { //~ERROR this `if` has the same condition as a previous if
315 //~^NOTE same as this
317 else if a == 1 { //~ERROR this `if` has the same condition as a previous if
321 //~^NOTE same as this
325 else if 2*a == 1 { //~ERROR this `if` has the same condition as a previous if
331 if cfg!(feature = "feature1-659") {
333 } else if cfg!(feature = "feature2-659") {
340 if v.pop() == None { // ok, functions
342 else if v.pop() == None {
345 if v.len() == 42 { // ok, functions
347 else if v.len() == 42 {