Skip to content

Commit 381e2e4

Browse files
committed
BinOpKind
1 parent d82dd75 commit 381e2e4

36 files changed

+260
-248
lines changed

clippy_lints/src/arithmetic.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
5757
match expr.node {
5858
hir::ExprKind::Binary(ref op, ref l, ref r) => {
5959
match op.node {
60-
hir::BiAnd
61-
| hir::BiOr
62-
| hir::BiBitAnd
63-
| hir::BiBitOr
64-
| hir::BiBitXor
65-
| hir::BiShl
66-
| hir::BiShr
67-
| hir::BiEq
68-
| hir::BiLt
69-
| hir::BiLe
70-
| hir::BiNe
71-
| hir::BiGe
72-
| hir::BiGt => return,
60+
hir::BinOpKind::And
61+
| hir::BinOpKind::Or
62+
| hir::BinOpKind::BitAnd
63+
| hir::BinOpKind::BitOr
64+
| hir::BinOpKind::BitXor
65+
| hir::BinOpKind::Shl
66+
| hir::BinOpKind::Shr
67+
| hir::BinOpKind::Eq
68+
| hir::BinOpKind::Lt
69+
| hir::BinOpKind::Le
70+
| hir::BinOpKind::Ne
71+
| hir::BinOpKind::Ge
72+
| hir::BinOpKind::Gt => return,
7373
_ => (),
7474
}
7575
let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r));

clippy_lints/src/assign_ops.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
175175
cx,
176176
ty,
177177
rty.into(),
178-
Add: BiAdd,
179-
Sub: BiSub,
180-
Mul: BiMul,
181-
Div: BiDiv,
182-
Rem: BiRem,
183-
And: BiAnd,
184-
Or: BiOr,
185-
BitAnd: BiBitAnd,
186-
BitOr: BiBitOr,
187-
BitXor: BiBitXor,
188-
Shr: BiShr,
189-
Shl: BiShl
178+
Add: BinOpKind::Add,
179+
Sub: BinOpKind::Sub,
180+
Mul: BinOpKind::Mul,
181+
Div: BinOpKind::Div,
182+
Rem: BinOpKind::Rem,
183+
And: BinOpKind::And,
184+
Or: BinOpKind::Or,
185+
BitAnd: BinOpKind::BitAnd,
186+
BitOr: BinOpKind::BitOr,
187+
BitXor: BinOpKind::BitXor,
188+
Shr: BinOpKind::Shr,
189+
Shl: BinOpKind::Shl
190190
) {
191191
span_lint_and_then(
192192
cx,
@@ -224,13 +224,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
224224
// a = b commutative_op a
225225
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) {
226226
match op.node {
227-
hir::BiAdd
228-
| hir::BiMul
229-
| hir::BiAnd
230-
| hir::BiOr
231-
| hir::BiBitXor
232-
| hir::BiBitAnd
233-
| hir::BiBitOr => {
227+
hirAdd
228+
| hir::BinOpKind::Mul
229+
| hir::BinOpKind::And
230+
| hir::BinOpKind::Or
231+
| hir::BinOpKind::BitXor
232+
| hir::BinOpKind::BitAnd
233+
| hir::BinOpKind::BitOr => {
234234
lint(assignee, l);
235235
},
236236
_ => {},
@@ -244,11 +244,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
244244
}
245245
}
246246

247-
fn is_commutative(op: hir::BinOp_) -> bool {
248-
use rustc::hir::BinOp_::*;
247+
fn is_commutative(op: hir::BinOpKind) -> bool {
248+
use rustc::hir::BinOpKind::*;
249249
match op {
250-
BiAdd | BiMul | BiAnd | BiOr | BiBitXor | BiBitAnd | BiBitOr | BiEq | BiNe => true,
251-
BiSub | BiDiv | BiRem | BiShl | BiShr | BiLt | BiLe | BiGe | BiGt => false,
250+
BinOpKind::Add | BinOpKind::Mul | BinOpKind::And | BinOpKind::Or | BinOpKind::BitXor | BinOpKind::BitAnd | BinOpKind::BitOr | BinOpKind::Eq | BinOpKind::Ne => true,
251+
BinOpKind::Sub | BinOpKind::Div | BinOpKind::Rem | BinOpKind::Shl | BinOpKind::Shr | BinOpKind::Lt | BinOpKind::Le | BinOpKind::Ge | BinOpKind::Gt => false,
252252
}
253253
}
254254

clippy_lints/src/bit_mask.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
120120
}
121121
if_chain! {
122122
if let ExprKind::Binary(ref op, ref left, ref right) = e.node;
123-
if BinOp_::BiEq == op.node;
123+
if BinOpKind::Eq == op.node;
124124
if let ExprKind::Binary(ref op1, ref left1, ref right1) = left.node;
125-
if BinOp_::BiBitAnd == op1.node;
125+
if BinOpKind::BitAnd == op1.node;
126126
if let ExprKind::Lit(ref lit) = right1.node;
127127
if let LitKind::Int(n, _) = lit.node;
128128
if let ExprKind::Lit(ref lit1) = right.node;
@@ -143,22 +143,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
143143
}
144144
}
145145

146-
fn invert_cmp(cmp: BinOp_) -> BinOp_ {
146+
fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
147147
match cmp {
148-
BiEq => BiEq,
149-
BiNe => BiNe,
150-
BiLt => BiGt,
151-
BiGt => BiLt,
152-
BiLe => BiGe,
153-
BiGe => BiLe,
154-
_ => BiOr, // Dummy
148+
BinOpKind::Eq => BinOpKind::Eq,
149+
BinOpKind::Ne => BinOpKind::Ne,
150+
BinOpKind::Lt => BinOpKind::Gt,
151+
BinOpKind::Gt => BinOpKind::Lt,
152+
BinOpKind::Le => BinOpKind::Ge,
153+
BinOpKind::Ge => BinOpKind::Le,
154+
_ => BinOpKind::Or, // Dummy
155155
}
156156
}
157157

158158

159-
fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u128, span: Span) {
159+
fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
160160
if let ExprKind::Binary(ref op, ref left, ref right) = bit_op.node {
161-
if op.node != BiBitAnd && op.node != BiBitOr {
161+
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
162162
return;
163163
}
164164
fetch_int_literal(cx, right)
@@ -167,10 +167,10 @@ fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u12
167167
}
168168
}
169169

170-
fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value: u128, cmp_value: u128, span: Span) {
170+
fn check_bit_mask(cx: &LateContext, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, cmp_value: u128, span: Span) {
171171
match cmp_op {
172-
BiEq | BiNe => match bit_op {
173-
BiBitAnd => if mask_value & cmp_value != cmp_value {
172+
BinOpKind::Eq | BinOpKind::Ne => match bit_op {
173+
BinOpKind::BitAnd => if mask_value & cmp_value != cmp_value {
174174
if cmp_value != 0 {
175175
span_lint(
176176
cx,
@@ -186,7 +186,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
186186
} else if mask_value == 0 {
187187
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
188188
},
189-
BiBitOr => if mask_value | cmp_value != cmp_value {
189+
BinOpKind::BitOr => if mask_value | cmp_value != cmp_value {
190190
span_lint(
191191
cx,
192192
BAD_BIT_MASK,
@@ -200,8 +200,8 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
200200
},
201201
_ => (),
202202
},
203-
BiLt | BiGe => match bit_op {
204-
BiBitAnd => if mask_value < cmp_value {
203+
BinOpKind::Lt | BinOpKind::Ge => match bit_op {
204+
BinOpKind::BitAnd => if mask_value < cmp_value {
205205
span_lint(
206206
cx,
207207
BAD_BIT_MASK,
@@ -215,7 +215,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
215215
} else if mask_value == 0 {
216216
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
217217
},
218-
BiBitOr => if mask_value >= cmp_value {
218+
BinOpKind::BitOr => if mask_value >= cmp_value {
219219
span_lint(
220220
cx,
221221
BAD_BIT_MASK,
@@ -229,11 +229,11 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
229229
} else {
230230
check_ineffective_lt(cx, span, mask_value, cmp_value, "|");
231231
},
232-
BiBitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"),
232+
BinOpKind::BitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"),
233233
_ => (),
234234
},
235-
BiLe | BiGt => match bit_op {
236-
BiBitAnd => if mask_value <= cmp_value {
235+
BinOpKind::Le | BinOpKind::Gt => match bit_op {
236+
BinOpKind::BitAnd => if mask_value <= cmp_value {
237237
span_lint(
238238
cx,
239239
BAD_BIT_MASK,
@@ -247,7 +247,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
247247
} else if mask_value == 0 {
248248
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
249249
},
250-
BiBitOr => if mask_value > cmp_value {
250+
BinOpKind::BitOr => if mask_value > cmp_value {
251251
span_lint(
252252
cx,
253253
BAD_BIT_MASK,
@@ -261,7 +261,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
261261
} else {
262262
check_ineffective_gt(cx, span, mask_value, cmp_value, "|");
263263
},
264-
BiBitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"),
264+
BinOpKind::BitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"),
265265
_ => (),
266266
},
267267
_ => (),

clippy_lints/src/booleans.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct Hir2Qmm<'a, 'tcx: 'a, 'v> {
8484
}
8585

8686
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
87-
fn extract(&mut self, op: BinOp_, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
87+
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
8888
for a in a {
8989
if let ExprKind::Binary(binop, ref lhs, ref rhs) = a.node {
9090
if binop.node == op {
@@ -103,8 +103,8 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
103103
match e.node {
104104
ExprKind::Unary(UnNot, ref inner) => return Ok(Bool::Not(box self.run(inner)?)),
105105
ExprKind::Binary(binop, ref lhs, ref rhs) => match binop.node {
106-
BiOr => return Ok(Bool::Or(self.extract(BiOr, &[lhs, rhs], Vec::new())?)),
107-
BiAnd => return Ok(Bool::And(self.extract(BiAnd, &[lhs, rhs], Vec::new())?)),
106+
BinOpKind::Or => return Ok(Bool::Or(self.extract(BinOpKind::Or, &[lhs, rhs], Vec::new())?)),
107+
BinOpKind::And => return Ok(Bool::And(self.extract(BinOpKind::And, &[lhs, rhs], Vec::new())?)),
108108
_ => (),
109109
},
110110
ExprKind::Lit(ref lit) => match lit.node {
@@ -137,12 +137,12 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
137137
}
138138
};
139139
match binop.node {
140-
BiEq => mk_expr(BiNe),
141-
BiNe => mk_expr(BiEq),
142-
BiGt => mk_expr(BiLe),
143-
BiGe => mk_expr(BiLt),
144-
BiLt => mk_expr(BiGe),
145-
BiLe => mk_expr(BiGt),
140+
BinOpKind::Eq => mk_expr(BinOpKind::Ne),
141+
BinOpKind::Ne => mk_expr(BinOpKind::Eq),
142+
BinOpKind::Gt => mk_expr(BinOpKind::Le),
143+
BinOpKind::Ge => mk_expr(BinOpKind::Lt),
144+
BinOpKind::Lt => mk_expr(BinOpKind::Ge),
145+
BinOpKind::Le => mk_expr(BinOpKind::Gt),
146146
_ => continue,
147147
}
148148
},
@@ -185,12 +185,12 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
185185
}
186186

187187
match binop.node {
188-
BiEq => Some(" != "),
189-
BiNe => Some(" == "),
190-
BiLt => Some(" >= "),
191-
BiGt => Some(" <= "),
192-
BiLe => Some(" > "),
193-
BiGe => Some(" < "),
188+
BinOpKind::Eq => Some(" != "),
189+
BinOpKind::Ne => Some(" == "),
190+
BinOpKind::Lt => Some(" >= "),
191+
BinOpKind::Gt => Some(" <= "),
192+
BinOpKind::Le => Some(" > "),
193+
BinOpKind::Ge => Some(" < "),
194194
_ => None,
195195
}.and_then(|op| Some(format!("{}{}{}", self.snip(lhs)?, op, self.snip(rhs)?)))
196196
},
@@ -441,7 +441,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
441441
return;
442442
}
443443
match e.node {
444-
ExprKind::Binary(binop, _, _) if binop.node == BiOr || binop.node == BiAnd => self.bool_expr(e),
444+
ExprKind::Binary(binop, _, _) if binop.node == BinOpKind::Or || binop.node == BinOpKind::And => self.bool_expr(e),
445445
ExprKind::Unary(UnNot, ref inner) => if self.cx.tables.node_types()[inner.hir_id].is_bool() {
446446
self.bool_expr(e);
447447
} else {

clippy_lints/src/bytecount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
5151
if body.arguments.len() == 1;
5252
if let Some(argname) = get_pat_name(&body.arguments[0].pat);
5353
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.node;
54-
if op.node == BiEq;
54+
if op.node == BinOpKind::Eq;
5555
if match_type(cx,
5656
walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])),
5757
&paths::SLICE_ITER);

0 commit comments

Comments
 (0)