Files
rust/tests/ui/if_not_else.fixed

80 lines
1.4 KiB
Rust
Raw Normal View History

#![warn(clippy::all)]
#![warn(clippy::if_not_else)]
fn foo() -> bool {
unimplemented!()
}
fn bla() -> bool {
unimplemented!()
}
fn main() {
if bla() {
println!("Bunny");
} else {
2025-02-12 23:44:38 +01:00
//~^ if_not_else
2025-02-11 17:57:08 +01:00
println!("Bugs");
}
if 4 == 5 {
println!("Bunny");
} else {
2025-02-12 23:44:38 +01:00
//~^ if_not_else
2025-02-11 17:57:08 +01:00
println!("Bugs");
}
if !foo() {
println!("Foo");
} else if !bla() {
println!("Bugs");
} else {
println!("Bunny");
}
2024-12-24 21:10:43 +09:00
if (foo() && bla()) {
println!("both true");
} else {
2025-02-12 23:44:38 +01:00
//~^ if_not_else
2024-12-24 21:10:43 +09:00
#[cfg(not(debug_assertions))]
println!("not debug");
#[cfg(debug_assertions)]
println!("debug");
if foo() {
println!("foo");
} else if bla() {
println!("bla");
} else {
println!("both false");
}
}
}
fn with_comments() {
if foo() {
println!("foo"); /* foo */
} else {
2025-02-12 23:44:38 +01:00
//~^ if_not_else
2024-12-24 21:10:43 +09:00
/* foo is false */
println!("foo is false");
}
if bla() {
println!("bla"); // bla
} else {
2025-02-12 23:44:38 +01:00
//~^ if_not_else
2024-12-24 21:10:43 +09:00
// bla is false
println!("bla");
}
}
fn with_annotations() {
#[cfg(debug_assertions)]
if foo() {
println!("foo"); /* foo */
} else {
2025-02-12 23:44:38 +01:00
//~^ if_not_else
2024-12-24 21:10:43 +09:00
/* foo is false */
println!("foo is false");
}
}