Skip to content

Commit de42dfb

Browse files
committed
Changes lint sugg to bitwise and operator &
1 parent bc48890 commit de42dfb

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

clippy_lints/src/needless_bool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
174174
)),
175175
ignore_case,
176176
Some((
177-
|l: Sugg<'_>, r: Sugg<'_>| (!l).and(&r),
177+
|l: Sugg<'_>, r: Sugg<'_>| (!l).bit_and(&r),
178178
"order comparisons between booleans can be simplified",
179179
)),
180180
),
@@ -189,7 +189,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
189189
ignore_case,
190190
Some((|h| h, "greater than checks against false are unnecessary")),
191191
Some((
192-
|l: Sugg<'_>, r: Sugg<'_>| l.and(&(!r)),
192+
|l: Sugg<'_>, r: Sugg<'_>| l.bit_and(&(!r)),
193193
"order comparisons between booleans can be simplified",
194194
)),
195195
),

clippy_lints/src/utils/sugg.rs

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ impl<'a> Sugg<'a> {
174174
make_binop(ast::BinOpKind::And, &self, rhs)
175175
}
176176

177+
/// Convenience method to create the `<lhs> & <rhs>` suggestion.
178+
pub fn bit_and(self, rhs: &Self) -> Sugg<'static> {
179+
make_binop(ast::BinOpKind::BitAnd, &self, rhs)
180+
}
181+
177182
/// Convenience method to create the `<lhs> as <rhs>` suggestion.
178183
pub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static> {
179184
make_assoc(AssocOp::As, &self, &Sugg::NonParen(rhs.to_string().into()))

tests/ui/bool_comparison.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ error: order comparisons between booleans can be simplified
7676
--> $DIR/bool_comparison.rs:74:8
7777
|
7878
74 | if x < y {
79-
| ^^^^^ help: try simplifying it as shown: `!x && y`
79+
| ^^^^^ help: try simplifying it as shown: `!x & y`
8080

8181
error: order comparisons between booleans can be simplified
8282
--> $DIR/bool_comparison.rs:79:8
8383
|
8484
79 | if x > y {
85-
| ^^^^^ help: try simplifying it as shown: `x && !y`
85+
| ^^^^^ help: try simplifying it as shown: `x & !y`
8686

8787
error: aborting due to 14 previous errors
8888

0 commit comments

Comments
 (0)