]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
Auto merge of #101846 - chenyukang:fix-101793, r=davidtwco
[rust.git] / src / tools / clippy / tests / ui / bool_to_int_with_if.fixed
1 // run-rustfix
2
3 #![warn(clippy::bool_to_int_with_if)]
4 #![allow(unused, dead_code, clippy::unnecessary_operation, clippy::no_effect)]
5
6 fn main() {
7     let a = true;
8     let b = false;
9
10     let x = 1;
11     let y = 2;
12
13     // Should lint
14     // precedence
15     i32::from(a);
16     i32::from(!a);
17     i32::from(a || b);
18     i32::from(cond(a, b));
19     i32::from(x + y < 4);
20
21     // if else if
22     if a {
23         123
24     } else {i32::from(b)};
25
26     // Shouldn't lint
27
28     if a {
29         1
30     } else if b {
31         0
32     } else {
33         3
34     };
35
36     if a {
37         3
38     } else if b {
39         1
40     } else {
41         -2
42     };
43
44     if a {
45         3
46     } else {
47         0
48     };
49     if a {
50         side_effect();
51         1
52     } else {
53         0
54     };
55     if a {
56         1
57     } else {
58         side_effect();
59         0
60     };
61
62     // multiple else ifs
63     if a {
64         123
65     } else if b {
66         1
67     } else if a | b {
68         0
69     } else {
70         123
71     };
72
73     some_fn(a);
74 }
75
76 // Lint returns and type inference
77 fn some_fn(a: bool) -> u8 {
78     u8::from(a)
79 }
80
81 fn side_effect() {}
82
83 fn cond(a: bool, b: bool) -> bool {
84     a || b
85 }