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.
12 #[warn(clippy::collapsible_if)]
18 println!("Hello world!");
22 if x == "hello" || x == "world" {
23 if y == "world" || y == "hello" {
24 println!("Hello world!");
28 if x == "hello" && x == "world" {
29 if y == "world" || y == "hello" {
30 println!("Hello world!");
34 if x == "hello" || x == "world" {
35 if y == "world" && y == "hello" {
36 println!("Hello world!");
40 if x == "hello" && x == "world" {
41 if y == "world" && y == "hello" {
42 println!("Hello world!");
52 // Collapse `else { if .. }` to `else if ..`
64 if let Some(42) = Some(42) {
83 if let Some(42) = Some(42) {
91 if let Some(42) = Some(42) {
94 if let Some(42) = Some(42) {
102 if let Some(42) = Some(42) {
113 if let Some(42) = Some(42) {
116 if let Some(42) = Some(42) {
124 // Works because any if with an else statement cannot be collapsed.
127 println!("Hello world!");
130 println!("Not Hello world");
135 println!("Hello world!");
137 println!("Hello something else");
150 assert!(true); // assert! is just an `if`
154 // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
155 if x == "hello" {// Not collapsible
157 println!("Hello world!");
161 if x == "hello" { // Not collapsible
163 println!("Hello world!");
170 println!("Hello world!");
175 if y == "world" { // Collapsible
176 println!("Hello world!");
193 if let Some(42) = Some(42) {
199 /* Not collapsible */
201 println!("Hello world!");
205 if x == "hello" { /* Not collapsible */
207 println!("Hello world!");