2015-05-29 16:07:34 +02:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
|
|
|
#[deny(collapsible_if)]
|
|
|
|
fn main() {
|
|
|
|
let x = "hello";
|
|
|
|
let y = "world";
|
2016-06-07 18:32:26 +02:00
|
|
|
if x == "hello" {
|
|
|
|
//~^ ERROR this if statement can be collapsed
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION if x == "hello" && y == "world" {
|
2015-05-29 16:07:34 +02:00
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 18:32:26 +02:00
|
|
|
if x == "hello" || x == "world" {
|
|
|
|
//~^ ERROR this if statement can be collapsed
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
|
2015-05-29 16:07:34 +02:00
|
|
|
if y == "world" || y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-13 18:32:55 +01:00
|
|
|
// Collaspe `else { if .. }` to `else if ..`
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
2016-06-21 23:53:45 +02:00
|
|
|
} else {
|
|
|
|
//~^ ERROR: this `else { if .. }`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION } else if y == "world"
|
2016-01-13 18:32:55 +01:00
|
|
|
if y == "world" {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
2016-06-21 23:53:45 +02:00
|
|
|
} else {
|
|
|
|
//~^ ERROR: this `else { if .. }`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION } else if let Some(42)
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
//~^ ERROR this `else { if .. }`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION } else if y == "world"
|
2016-01-13 18:32:55 +01:00
|
|
|
if y == "world" {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 23:53:45 +02:00
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
//~^ ERROR this `else { if .. }`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION } else if let Some(42)
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
//~^ ERROR this `else { if .. }`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION } else if let Some(42)
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
//~^ ERROR this `else { if .. }`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION } else if x == "hello"
|
|
|
|
if x == "hello" {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
//~^ ERROR this `else { if .. }`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION } else if let Some(42)
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
println!("!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 16:07:34 +02:00
|
|
|
// Works because any if with an else statement cannot be collapsed.
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("Not Hello world");
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
} else {
|
|
|
|
println!("Hello something else");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 20:22:20 +02:00
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
if y == "world" {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
2015-05-29 16:07:34 +02:00
|
|
|
}
|