summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/clippy_lints/src/precedence.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/clippy_lints/src/precedence.rs')
-rw-r--r--src/tools/clippy/clippy_lints/src/precedence.rs45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/tools/clippy/clippy_lints/src/precedence.rs b/src/tools/clippy/clippy_lints/src/precedence.rs
index 057b7e306..ff83725da 100644
--- a/src/tools/clippy/clippy_lints/src/precedence.rs
+++ b/src/tools/clippy/clippy_lints/src/precedence.rs
@@ -1,11 +1,10 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
-use if_chain::if_chain;
use rustc_ast::ast::{BinOpKind, Expr, ExprKind, MethodCall, UnOp};
use rustc_ast::token;
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
-use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_session::declare_lint_pass;
use rustc_span::source_map::Spanned;
const ALLOWED_ODD_FUNCTIONS: [&str; 14] = [
@@ -79,7 +78,7 @@ impl EarlyLintPass for Precedence {
let sugg = format!(
"({}) {} ({})",
snippet_with_applicability(cx, left.span, "..", &mut applicability),
- op.to_string(),
+ op.as_str(),
snippet_with_applicability(cx, right.span, "..", &mut applicability)
);
span_sugg(expr, sugg, applicability);
@@ -88,7 +87,7 @@ impl EarlyLintPass for Precedence {
let sugg = format!(
"({}) {} {}",
snippet_with_applicability(cx, left.span, "..", &mut applicability),
- op.to_string(),
+ op.as_str(),
snippet_with_applicability(cx, right.span, "..", &mut applicability)
);
span_sugg(expr, sugg, applicability);
@@ -97,7 +96,7 @@ impl EarlyLintPass for Precedence {
let sugg = format!(
"{} {} ({})",
snippet_with_applicability(cx, left.span, "..", &mut applicability),
- op.to_string(),
+ op.as_str(),
snippet_with_applicability(cx, right.span, "..", &mut applicability)
);
span_sugg(expr, sugg, applicability);
@@ -118,25 +117,23 @@ impl EarlyLintPass for Precedence {
arg = receiver;
}
- if_chain! {
- if !all_odd;
- if let ExprKind::Lit(lit) = &arg.kind;
- if let token::LitKind::Integer | token::LitKind::Float = &lit.kind;
- then {
- let mut applicability = Applicability::MachineApplicable;
- span_lint_and_sugg(
- cx,
- PRECEDENCE,
- expr.span,
- "unary minus has lower precedence than method call",
- "consider adding parentheses to clarify your intent",
- format!(
- "-({})",
- snippet_with_applicability(cx, operand.span, "..", &mut applicability)
- ),
- applicability,
- );
- }
+ if !all_odd
+ && let ExprKind::Lit(lit) = &arg.kind
+ && let token::LitKind::Integer | token::LitKind::Float = &lit.kind
+ {
+ let mut applicability = Applicability::MachineApplicable;
+ span_lint_and_sugg(
+ cx,
+ PRECEDENCE,
+ expr.span,
+ "unary minus has lower precedence than method call",
+ "consider adding parentheses to clarify your intent",
+ format!(
+ "-({})",
+ snippet_with_applicability(cx, operand.span, "..", &mut applicability)
+ ),
+ applicability,
+ );
}
}
}