diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index dbd61935c..1ad7f4c55 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -174,7 +174,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { )), ignore_case, Some(( - |l: Sugg<'_>, r: Sugg<'_>| (!l).and(&r), + |l: Sugg<'_>, r: Sugg<'_>| (!l).bit_and(&r), "order comparisons between booleans can be simplified", )), ), @@ -189,7 +189,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison { ignore_case, Some((|h| h, "greater than checks against false are unnecessary")), Some(( - |l: Sugg<'_>, r: Sugg<'_>| l.and(&(!r)), + |l: Sugg<'_>, r: Sugg<'_>| l.bit_and(&(!r)), "order comparisons between booleans can be simplified", )), ), diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index c5f4a61fe..66f18b51f 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -174,6 +174,11 @@ impl<'a> Sugg<'a> { make_binop(ast::BinOpKind::And, &self, rhs) } + /// Convenience method to create the ` & ` suggestion. + pub fn bit_and(self, rhs: &Self) -> Sugg<'static> { + make_binop(ast::BinOpKind::BitAnd, &self, rhs) + } + /// Convenience method to create the ` as ` suggestion. pub fn as_ty(self, rhs: R) -> Sugg<'static> { make_assoc(AssocOp::As, &self, &Sugg::NonParen(rhs.to_string().into())) diff --git a/tests/ui/bool_comparison.stderr b/tests/ui/bool_comparison.stderr index d28052676..9a12a8f08 100644 --- a/tests/ui/bool_comparison.stderr +++ b/tests/ui/bool_comparison.stderr @@ -76,13 +76,13 @@ error: order comparisons between booleans can be simplified --> $DIR/bool_comparison.rs:74:8 | 74 | if x < y { - | ^^^^^ help: try simplifying it as shown: `!x && y` + | ^^^^^ help: try simplifying it as shown: `!x & y` error: order comparisons between booleans can be simplified --> $DIR/bool_comparison.rs:79:8 | 79 | if x > y { - | ^^^^^ help: try simplifying it as shown: `x && !y` + | ^^^^^ help: try simplifying it as shown: `x & !y` error: aborting due to 14 previous errors