Changes lint sugg to bitwise and operator &

This commit is contained in:
Lucas Lois 2018-12-17 15:32:24 -03:00
parent bc48890b47
commit de42dfbab7
3 changed files with 9 additions and 4 deletions

View file

@ -174,7 +174,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
)), )),
ignore_case, ignore_case,
Some(( Some((
|l: Sugg<'_>, r: Sugg<'_>| (!l).and(&r), |l: Sugg<'_>, r: Sugg<'_>| (!l).bit_and(&r),
"order comparisons between booleans can be simplified", "order comparisons between booleans can be simplified",
)), )),
), ),
@ -189,7 +189,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
ignore_case, ignore_case,
Some((|h| h, "greater than checks against false are unnecessary")), Some((|h| h, "greater than checks against false are unnecessary")),
Some(( Some((
|l: Sugg<'_>, r: Sugg<'_>| l.and(&(!r)), |l: Sugg<'_>, r: Sugg<'_>| l.bit_and(&(!r)),
"order comparisons between booleans can be simplified", "order comparisons between booleans can be simplified",
)), )),
), ),

View file

@ -174,6 +174,11 @@ impl<'a> Sugg<'a> {
make_binop(ast::BinOpKind::And, &self, rhs) 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. /// Convenience method to create the `<lhs> as <rhs>` suggestion.
pub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static> { pub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static> {
make_assoc(AssocOp::As, &self, &Sugg::NonParen(rhs.to_string().into())) make_assoc(AssocOp::As, &self, &Sugg::NonParen(rhs.to_string().into()))

View file

@ -76,13 +76,13 @@ error: order comparisons between booleans can be simplified
--> $DIR/bool_comparison.rs:74:8 --> $DIR/bool_comparison.rs:74:8
| |
74 | if x < y { 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 error: order comparisons between booleans can be simplified
--> $DIR/bool_comparison.rs:79:8 --> $DIR/bool_comparison.rs:79:8
| |
79 | if x > y { 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 error: aborting due to 14 previous errors