1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
14 #[warn(clippy::collapsible_if)]
20 println!("Hello world!");
24 if x == "hello" || x == "world" {
25 if y == "world" || y == "hello" {
26 println!("Hello world!");
30 if x == "hello" && x == "world" {
31 if y == "world" || y == "hello" {
32 println!("Hello world!");
36 if x == "hello" || x == "world" {
37 if y == "world" && y == "hello" {
38 println!("Hello world!");
42 if x == "hello" && x == "world" {
43 if y == "world" && y == "hello" {
44 println!("Hello world!");
54 // Collapse `else { if .. }` to `else if ..`
66 if let Some(42) = Some(42) {
85 if let Some(42) = Some(42) {
93 if let Some(42) = Some(42) {
96 if let Some(42) = Some(42) {
104 if let Some(42) = Some(42) {
115 if let Some(42) = Some(42) {
118 if let Some(42) = Some(42) {
126 // Works because any if with an else statement cannot be collapsed.
129 println!("Hello world!");
132 println!("Not Hello world");
137 println!("Hello world!");
139 println!("Hello something else");
152 assert!(true); // assert! is just an `if`
156 // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
157 if x == "hello" {// Not collapsible
159 println!("Hello world!");
163 if x == "hello" { // Not collapsible
165 println!("Hello world!");
172 println!("Hello world!");
177 if y == "world" { // Collapsible
178 println!("Hello world!");
195 if let Some(42) = Some(42) {
201 /* Not collapsible */
203 println!("Hello world!");
207 if x == "hello" { /* Not collapsible */
209 println!("Hello world!");