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.
11 #[warn(clippy::collapsible_if)]
17 println!("Hello world!");
21 if x == "hello" || x == "world" {
22 if y == "world" || y == "hello" {
23 println!("Hello world!");
27 if x == "hello" && x == "world" {
28 if y == "world" || y == "hello" {
29 println!("Hello world!");
33 if x == "hello" || x == "world" {
34 if y == "world" && y == "hello" {
35 println!("Hello world!");
39 if x == "hello" && x == "world" {
40 if y == "world" && y == "hello" {
41 println!("Hello world!");
51 // Collapse `else { if .. }` to `else if ..`
63 if let Some(42) = Some(42) {
82 if let Some(42) = Some(42) {
90 if let Some(42) = Some(42) {
93 if let Some(42) = Some(42) {
101 if let Some(42) = Some(42) {
112 if let Some(42) = Some(42) {
115 if let Some(42) = Some(42) {
123 // Works because any if with an else statement cannot be collapsed.
126 println!("Hello world!");
129 println!("Not Hello world");
134 println!("Hello world!");
136 println!("Hello something else");
149 assert!(true); // assert! is just an `if`
153 // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
154 if x == "hello" {// Not collapsible
156 println!("Hello world!");
160 if x == "hello" { // Not collapsible
162 println!("Hello world!");
169 println!("Hello world!");
174 if y == "world" { // Collapsible
175 println!("Hello world!");
192 if let Some(42) = Some(42) {
198 /* Not collapsible */
200 println!("Hello world!");
204 if x == "hello" { /* Not collapsible */
206 println!("Hello world!");