]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_bitwise_bool.rs
Fix adjacent code
[rust.git] / tests / ui / needless_bitwise_bool.rs
1 // run-rustfix
2
3 #![warn(clippy::needless_bitwise_bool)]
4
5 fn returns_bool() -> bool {
6     true
7 }
8
9 const fn const_returns_bool() -> bool {
10     false
11 }
12
13 fn main() {
14     let (x, y) = (false, true);
15     if x & y {
16         println!("true")
17     }
18     if returns_bool() & x {
19         println!("true")
20     }
21     if !returns_bool() & returns_bool() {
22         println!("true")
23     }
24     if y & !x {
25         println!("true")
26     }
27
28     // BELOW: lints we hope to catch as `Expr::can_have_side_effects` improves.
29     if y & !const_returns_bool() {
30         println!("true") // This is a const function, in an UnOp
31     }
32
33     if y & "abcD".is_empty() {
34         println!("true") // This is a const method call
35     }
36
37     if y & (0 < 1) {
38         println!("true") // This is a BinOp with no side effects
39     }
40 }