You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[bad_bit_mask](https://github.com/Manishearth/rust-clippy/wiki#bad_bit_mask) | warn | expressions of the form `_ & mask == select` that will only ever return `true` or `false` (because in the example `select` containing bits that `mask` doesn't have)
16
16
[block_in_if_condition_expr](https://github.com/Manishearth/rust-clippy/wiki#block_in_if_condition_expr) | warn | braces can be eliminated in conditions that are expressions, e.g `if { true } ...`
17
17
[block_in_if_condition_stmt](https://github.com/Manishearth/rust-clippy/wiki#block_in_if_condition_stmt) | warn | avoid complex blocks in conditions, instead move the block higher and bind it with 'let'; e.g: `if { let x = true; x } ...`
18
+
[bool_comparison](https://github.com/Manishearth/rust-clippy/wiki#bool_comparison) | warn | comparing a variable to a boolean, e.g. `if x == true`
18
19
[box_vec](https://github.com/Manishearth/rust-clippy/wiki#box_vec) | warn | usage of `Box<Vec<T>>`, vector elements are already on the heap
19
20
[boxed_local](https://github.com/Manishearth/rust-clippy/wiki#boxed_local) | warn | using Box<T> where unnecessary
20
21
[cast_possible_truncation](https://github.com/Manishearth/rust-clippy/wiki#cast_possible_truncation) | allow | casts that may cause truncation of the value, e.g `x as u8` where `x: u32`, or `x as i32` where `x: f32`
Copy file name to clipboardExpand all lines: src/needless_bool.rs
+75-1Lines changed: 75 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,9 @@ use rustc::lint::*;
6
6
use rustc_front::hir::*;
7
7
8
8
use syntax::ast::Lit_;
9
+
use syntax::codemap::Spanned;
9
10
10
-
use utils::{span_lint, snippet};
11
+
use utils::{span_lint,span_lint_and_then,snippet};
11
12
12
13
/// **What it does:** This lint checks for expressions of the form `if c { true } else { false }` (or vice versa) and suggest using the condition directly.
13
14
///
@@ -23,6 +24,20 @@ declare_lint! {
23
24
`if p { true } else { false }`"
24
25
}
25
26
27
+
/// **What it does:** This lint checks for expressions of the form `x == true` (or vice versa) and suggest using the variable directly.
28
+
///
29
+
/// **Why is this bad?** Unnecessary code.
30
+
///
31
+
/// **Known problems:** None.
32
+
///
33
+
/// **Example:** `if x == true { }` could be `if x { }`
34
+
declare_lint!{
35
+
pubBOOL_COMPARISON,
36
+
Warn,
37
+
"comparing a variable to a boolean, e.g. \
38
+
`if x == true`"
39
+
}
40
+
26
41
#[derive(Copy,Clone)]
27
42
pubstructNeedlessBool;
28
43
@@ -78,6 +93,65 @@ impl LateLintPass for NeedlessBool {
0 commit comments