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