Skip to content

Commit efbf7ca

Browse files
committed
Use From to convert BinOpKind
1 parent e9c3991 commit efbf7ca

File tree

4 files changed

+4
-29
lines changed

4 files changed

+4
-29
lines changed

clippy_lints/src/assign_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet_opt;
33
use clippy_utils::ty::implements_trait;
44
use clippy_utils::{eq_expr_value, get_trait_def_id, trait_ref_of_method};
5-
use clippy_utils::{higher, paths, sugg};
5+
use clippy_utils::{paths, sugg};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir as hir;
@@ -206,7 +206,7 @@ fn lint_misrefactored_assign_op(
206206
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span)) {
207207
let a = &sugg::Sugg::hir(cx, assignee, "..");
208208
let r = &sugg::Sugg::hir(cx, rhs, "..");
209-
let long = format!("{} = {}", snip_a, sugg::make_binop(higher::binop(op.node), a, r));
209+
let long = format!("{} = {}", snip_a, sugg::make_binop(op.node.into(), a, r));
210210
diag.span_suggestion(
211211
expr.span,
212212
&format!(

clippy_lints/src/eq_op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
102102
if macro_with_not_op(&left.kind) || macro_with_not_op(&right.kind) {
103103
return;
104104
}
105-
if is_useless_with_eq_exprs(higher::binop(op.node)) && eq_expr_value(cx, left, right) {
105+
if is_useless_with_eq_exprs(op.node.into()) && eq_expr_value(cx, left, right) {
106106
span_lint(
107107
cx,
108108
EQ_OP,

clippy_utils/src/higher.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,6 @@ use rustc_hir::{BorrowKind, Expr, ExprKind, StmtKind, UnOp};
1111
use rustc_lint::LateContext;
1212
use rustc_span::{sym, ExpnKind, Span, Symbol};
1313

14-
/// Converts a hir binary operator to the corresponding `ast` type.
15-
#[must_use]
16-
pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind {
17-
match op {
18-
hir::BinOpKind::Eq => ast::BinOpKind::Eq,
19-
hir::BinOpKind::Ge => ast::BinOpKind::Ge,
20-
hir::BinOpKind::Gt => ast::BinOpKind::Gt,
21-
hir::BinOpKind::Le => ast::BinOpKind::Le,
22-
hir::BinOpKind::Lt => ast::BinOpKind::Lt,
23-
hir::BinOpKind::Ne => ast::BinOpKind::Ne,
24-
hir::BinOpKind::Or => ast::BinOpKind::Or,
25-
hir::BinOpKind::Add => ast::BinOpKind::Add,
26-
hir::BinOpKind::And => ast::BinOpKind::And,
27-
hir::BinOpKind::BitAnd => ast::BinOpKind::BitAnd,
28-
hir::BinOpKind::BitOr => ast::BinOpKind::BitOr,
29-
hir::BinOpKind::BitXor => ast::BinOpKind::BitXor,
30-
hir::BinOpKind::Div => ast::BinOpKind::Div,
31-
hir::BinOpKind::Mul => ast::BinOpKind::Mul,
32-
hir::BinOpKind::Rem => ast::BinOpKind::Rem,
33-
hir::BinOpKind::Shl => ast::BinOpKind::Shl,
34-
hir::BinOpKind::Shr => ast::BinOpKind::Shr,
35-
hir::BinOpKind::Sub => ast::BinOpKind::Sub,
36-
}
37-
}
38-
3914
/// Represent a range akin to `ast::ExprKind::Range`.
4015
#[derive(Debug, Copy, Clone)]
4116
pub struct Range<'a> {

clippy_utils/src/sugg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a> Sugg<'a> {
154154
| hir::ExprKind::Err => Sugg::NonParen(snippet),
155155
hir::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet),
156156
hir::ExprKind::AssignOp(op, ..) => Sugg::BinOp(hirbinop2assignop(op), snippet),
157-
hir::ExprKind::Binary(op, ..) => Sugg::BinOp(AssocOp::from_ast_binop(higher::binop(op.node)), snippet),
157+
hir::ExprKind::Binary(op, ..) => Sugg::BinOp(AssocOp::from_ast_binop(op.node.into()), snippet),
158158
hir::ExprKind::Cast(..) => Sugg::BinOp(AssocOp::As, snippet),
159159
hir::ExprKind::Type(..) => Sugg::BinOp(AssocOp::Colon, snippet),
160160
}

0 commit comments

Comments
 (0)