mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Changes lint sugg to bitwise and operator &
This commit is contained in:
parent
bc48890b47
commit
de42dfbab7
3 changed files with 9 additions and 4 deletions
|
@ -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",
|
||||
)),
|
||||
),
|
||||
|
|
|
@ -174,6 +174,11 @@ impl<'a> Sugg<'a> {
|
|||
make_binop(ast::BinOpKind::And, &self, rhs)
|
||||
}
|
||||
|
||||
/// Convenience method to create the `<lhs> & <rhs>` suggestion.
|
||||
pub fn bit_and(self, rhs: &Self) -> Sugg<'static> {
|
||||
make_binop(ast::BinOpKind::BitAnd, &self, rhs)
|
||||
}
|
||||
|
||||
/// Convenience method to create the `<lhs> as <rhs>` suggestion.
|
||||
pub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static> {
|
||||
make_assoc(AssocOp::As, &self, &Sugg::NonParen(rhs.to_string().into()))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue