mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
use let chains in bit_mask.rs
This commit is contained in:
parent
4667198d4f
commit
5e4f092291
1 changed files with 20 additions and 20 deletions
|
@ -1,7 +1,6 @@
|
||||||
use clippy_utils::consts::{constant, Constant};
|
use clippy_utils::consts::{constant, Constant};
|
||||||
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
|
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
|
||||||
use clippy_utils::sugg::Sugg;
|
use clippy_utils::sugg::Sugg;
|
||||||
use if_chain::if_chain;
|
|
||||||
use rustc_ast::ast::LitKind;
|
use rustc_ast::ast::LitKind;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{BinOpKind, Expr, ExprKind};
|
use rustc_hir::{BinOpKind, Expr, ExprKind};
|
||||||
|
@ -130,23 +129,24 @@ impl<'tcx> LateLintPass<'tcx> for BitMask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if_chain! {
|
|
||||||
if let ExprKind::Binary(op, left, right) = &e.kind;
|
if let ExprKind::Binary(op, left, right) = &e.kind
|
||||||
if BinOpKind::Eq == op.node;
|
&& BinOpKind::Eq == op.node
|
||||||
if let ExprKind::Binary(op1, left1, right1) = &left.kind;
|
&& let ExprKind::Binary(op1, left1, right1) = &left.kind
|
||||||
if BinOpKind::BitAnd == op1.node;
|
&& BinOpKind::BitAnd == op1.node
|
||||||
if let ExprKind::Lit(lit) = &right1.kind;
|
&& let ExprKind::Lit(lit) = &right1.kind
|
||||||
if let LitKind::Int(n, _) = lit.node;
|
&& let LitKind::Int(n, _) = lit.node
|
||||||
if let ExprKind::Lit(lit1) = &right.kind;
|
&& let ExprKind::Lit(lit1) = &right.kind
|
||||||
if let LitKind::Int(0, _) = lit1.node;
|
&& let LitKind::Int(0, _) = lit1.node
|
||||||
if n.leading_zeros() == n.count_zeros();
|
&& n.leading_zeros() == n.count_zeros()
|
||||||
if n > u128::from(self.verbose_bit_mask_threshold);
|
&& n > u128::from(self.verbose_bit_mask_threshold)
|
||||||
then {
|
{
|
||||||
span_lint_and_then(cx,
|
span_lint_and_then(
|
||||||
VERBOSE_BIT_MASK,
|
cx,
|
||||||
e.span,
|
VERBOSE_BIT_MASK,
|
||||||
"bit mask could be simplified with a call to `trailing_zeros`",
|
e.span,
|
||||||
|diag| {
|
"bit mask could be simplified with a call to `trailing_zeros`",
|
||||||
|
|diag| {
|
||||||
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
|
let sugg = Sugg::hir(cx, left1, "...").maybe_par();
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
|
@ -154,8 +154,8 @@ impl<'tcx> LateLintPass<'tcx> for BitMask {
|
||||||
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
|
format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue