fmt clippy
This commit is contained in:
parent
839ad09689
commit
c9342d0121
41 changed files with 2187 additions and 1488 deletions
|
|
@ -31,29 +31,40 @@ impl LintPass for Precedence {
|
|||
impl EarlyLintPass for Precedence {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
||||
if let ExprBinary(Spanned { node: op, ..}, ref left, ref right) = expr.node {
|
||||
if !is_bit_op(op) { return; }
|
||||
if !is_bit_op(op) {
|
||||
return;
|
||||
}
|
||||
match (is_arith_expr(left), is_arith_expr(right)) {
|
||||
(true, true) => {
|
||||
span_lint(cx, PRECEDENCE, expr.span,
|
||||
&format!("operator precedence can trip the unwary. \
|
||||
Consider parenthesizing your expression:\
|
||||
`({}) {} ({})`", snippet(cx, left.span, ".."),
|
||||
op.to_string(), snippet(cx, right.span, "..")));
|
||||
},
|
||||
span_lint(cx,
|
||||
PRECEDENCE,
|
||||
expr.span,
|
||||
&format!("operator precedence can trip the unwary. Consider parenthesizing your \
|
||||
expression:`({}) {} ({})`",
|
||||
snippet(cx, left.span, ".."),
|
||||
op.to_string(),
|
||||
snippet(cx, right.span, "..")));
|
||||
}
|
||||
(true, false) => {
|
||||
span_lint(cx, PRECEDENCE, expr.span,
|
||||
&format!("operator precedence can trip the unwary. \
|
||||
Consider parenthesizing your expression:\
|
||||
`({}) {} {}`", snippet(cx, left.span, ".."),
|
||||
op.to_string(), snippet(cx, right.span, "..")));
|
||||
},
|
||||
span_lint(cx,
|
||||
PRECEDENCE,
|
||||
expr.span,
|
||||
&format!("operator precedence can trip the unwary. Consider parenthesizing your \
|
||||
expression:`({}) {} {}`",
|
||||
snippet(cx, left.span, ".."),
|
||||
op.to_string(),
|
||||
snippet(cx, right.span, "..")));
|
||||
}
|
||||
(false, true) => {
|
||||
span_lint(cx, PRECEDENCE, expr.span,
|
||||
&format!("operator precedence can trip the unwary. \
|
||||
Consider parenthesizing your expression:\
|
||||
`{} {} ({})`", snippet(cx, left.span, ".."),
|
||||
op.to_string(), snippet(cx, right.span, "..")));
|
||||
},
|
||||
span_lint(cx,
|
||||
PRECEDENCE,
|
||||
expr.span,
|
||||
&format!("operator precedence can trip the unwary. Consider parenthesizing your \
|
||||
expression:`{} {} ({})`",
|
||||
snippet(cx, left.span, ".."),
|
||||
op.to_string(),
|
||||
snippet(cx, right.span, "..")));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
@ -64,13 +75,14 @@ impl EarlyLintPass for Precedence {
|
|||
if let ExprLit(ref lit) = slf.node {
|
||||
match lit.node {
|
||||
LitInt(..) | LitFloat(..) | LitFloatUnsuffixed(..) => {
|
||||
span_lint(cx, PRECEDENCE, expr.span, &format!(
|
||||
"unary minus has lower precedence than \
|
||||
method call. Consider adding parentheses \
|
||||
to clarify your intent: -({})",
|
||||
snippet(cx, rhs.span, "..")));
|
||||
span_lint(cx,
|
||||
PRECEDENCE,
|
||||
expr.span,
|
||||
&format!("unary minus has lower precedence than method call. Consider \
|
||||
adding parentheses to clarify your intent: -({})",
|
||||
snippet(cx, rhs.span, "..")));
|
||||
}
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -82,20 +94,20 @@ impl EarlyLintPass for Precedence {
|
|||
fn is_arith_expr(expr: &Expr) -> bool {
|
||||
match expr.node {
|
||||
ExprBinary(Spanned { node: op, ..}, _, _) => is_arith_op(op),
|
||||
_ => false
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_bit_op(op: BinOp_) -> bool {
|
||||
match op {
|
||||
BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => true,
|
||||
_ => false
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_arith_op(op: BinOp_) -> bool {
|
||||
match op {
|
||||
BiAdd | BiSub | BiMul | BiDiv | BiRem => true,
|
||||
_ => false
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue