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)]
14 fn foo() -> bool { unimplemented!() }
20 #[deny(if_same_then_else)]
21 #[deny(match_same_arms)]
22 fn if_same_then_else() -> Result<&'static str, ()> {
33 else { //~ERROR this `if` has identical blocks
70 else { //~ERROR this `if` has identical blocks
83 else { //~ERROR this `if` has identical blocks
96 while foo() { break; }
99 else { //~ERROR this `if` has identical blocks
107 while foo() { break; }
112 //~^NOTE same as this
123 else if foo() { //~ERROR this `if` has identical blocks
133 //~^NOTE same as this
134 if let Some(a) = Some(42) {}
136 else { //~ERROR this `if` has identical blocks
137 if let Some(a) = Some(42) {}
141 //~^NOTE same as this
142 if let (1, .., 3) = (1, 2, 3) {}
144 else { //~ERROR this `if` has identical blocks
145 if let (1, .., 3) = (1, 2, 3) {}
149 if let (1, .., 3) = (1, 2, 3) {}
152 if let (.., 3) = (1, 2, 3) {}
156 if let (1, .., 3) = (1, 2, 3) {}
159 if let (.., 4) = (1, 2, 3) {}
163 if let (1, .., 3) = (1, 2, 3) {}
166 if let (.., 1, 3) = (1, 2, 3) {}
170 if let Some(a) = Some(42) {}
173 if let Some(a) = Some(43) {}
178 //~^NOTE same as this
180 51 => foo(), //~ERROR this `match` has identical arm bodies
184 let _ = match Some(42) {
186 //~^NOTE same as this
187 //~|NOTE `Some(_) | None`
188 None => 24, //~ERROR this `match` has identical arm bodies
191 let _ = match Some(42) {
196 let _ = match Some(42) {
198 Some(a) => 24, // bindings are different
202 let _ = match Some(42) {
203 Some(a) if a > 0 => 24,
204 Some(a) => 24, // one arm has a guard
208 match (Some(42), Some(42)) {
209 (Some(a), None) => bar(a),
210 //~^NOTE same as this
211 //~|NOTE `(Some(a), None) | (None, Some(a))`
212 (None, Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
216 match (Some(42), Some(42)) {
217 (Some(a), ..) => bar(a),
218 //~^NOTE same as this
219 //~|NOTE `(Some(a), ..) | (.., Some(a))`
220 (.., Some(a)) => bar(a), //~ERROR this `match` has identical arm bodies
226 //~^NOTE same as this
227 //~|NOTE `(1, .., 3) | (.., 3)`
228 (.., 3) => 42, //~ERROR this `match` has identical arm bodies
232 match (Some(42), Some("")) {
233 (Some(a), None) => bar(a),
234 (None, Some(a)) => bar(a), // bindings have different types
239 //~^NOTE same as this
242 else { //~ERROR this `if` has identical blocks
247 //~^NOTE same as this
249 return Ok(&foo[0..]);
253 return Ok(&foo[0..]);
255 else { //~ERROR this `if` has identical blocks
257 return Ok(&foo[0..]);
261 #[deny(ifs_same_cond)]
262 #[allow(if_same_then_else)] // all empty blocks
268 //~^NOTE same as this
270 else if b { //~ERROR this `if` has the same condition as a previous if
274 //~^NOTE same as this
276 else if a == 1 { //~ERROR this `if` has the same condition as a previous if
280 //~^NOTE same as this
284 else if 2*a == 1 { //~ERROR this `if` has the same condition as a previous if
290 if cfg!(feature = "feature1-659") {
292 } else if cfg!(feature = "feature2-659") {
299 if v.pop() == None { // ok, functions
301 else if v.pop() == None {
304 if v.len() == 42 { // ok, functions
306 else if v.len() == 42 {