rust/tests/ui/match_bool.fixed
Samuel Tardieu b8275293ba Don't use labeled block as top-level blocks
Labeled blocks cannot be used as-is in the "then" or "else" part of an
`if` expression. They must be enclosed in an anonymous block.
2025-01-29 18:46:38 +01:00

65 lines
1.1 KiB
Rust

#![deny(clippy::match_bool)]
#![allow(clippy::nonminimal_bool, clippy::eq_op)]
fn match_bool() {
let test: bool = true;
if test { 0 } else { 42 };
let option = 1;
if option == 1 { 1 } else { 0 };
if !test {
println!("Noooo!");
};
if !test {
println!("Noooo!");
};
if !(test && test) {
println!("Noooo!");
};
if !test {
println!("Noooo!");
} else {
println!("Yes!");
};
// Not linted
match option {
1..=10 => 1,
11..=20 => 2,
_ => 3,
};
// Don't lint
let _ = match test {
#[cfg(feature = "foo")]
true if option == 5 => 10,
true => 0,
false => 1,
};
let _ = if test && option == 5 { 10 } else { 1 };
let _ = if !test && option == 5 { 10 } else { 1 };
if test && option == 5 { println!("Hello") };
if !(test && option == 5) { println!("Hello") };
if !test && option == 5 { println!("Hello") };
if !(!test && option == 5) { println!("Hello") };
}
fn issue14099() {
if true { 'a: {
break 'a;
} }
}
fn main() {}