Skip to content

Commit 406e89a

Browse files
committed
Auto merge of #4601 - lzutao:clean-up-unused-vars, r=phansch
Clean up some unused vars changelog: none
2 parents b292183 + aa4f3fb commit 406e89a

File tree

4 files changed

+23
-48
lines changed

4 files changed

+23
-48
lines changed

clippy_lints/src/erasing_op.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
4848
}
4949

5050
fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) {
51-
if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
52-
if v == 0 {
53-
span_lint(
54-
cx,
55-
ERASING_OP,
56-
span,
57-
"this operation will always return zero. This is likely not the intended outcome",
58-
);
59-
}
51+
if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) {
52+
span_lint(
53+
cx,
54+
ERASING_OP,
55+
span,
56+
"this operation will always return zero. This is likely not the intended outcome",
57+
);
6058
}
6159
}

clippy_lints/src/get_last_with_len.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
7979

8080
// RHS of subtraction is 1
8181
if let ExprKind::Lit(rhs_lit) = &rhs.kind;
82-
if let LitKind::Int(rhs_value, ..) = rhs_lit.node;
83-
if rhs_value == 1;
82+
if let LitKind::Int(1, ..) = rhs_lit.node;
8483

8584
then {
8685
let mut applicability = Applicability::MachineApplicable;

clippy_lints/src/neg_multiply.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use if_chain::if_chain;
22
use rustc::hir::*;
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_lint_pass, declare_tool_lint};
5-
use syntax::source_map::{Span, Spanned};
5+
use syntax::source_map::Span;
66

77
use crate::consts::{self, Constant};
88
use crate::utils::span_lint;
@@ -28,19 +28,14 @@ declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
2828
#[allow(clippy::match_same_arms)]
2929
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
3030
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
31-
if let ExprKind::Binary(
32-
Spanned {
33-
node: BinOpKind::Mul, ..
34-
},
35-
ref l,
36-
ref r,
37-
) = e.kind
38-
{
39-
match (&l.kind, &r.kind) {
40-
(&ExprKind::Unary(..), &ExprKind::Unary(..)) => (),
41-
(&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, r),
42-
(_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, l),
43-
_ => (),
31+
if let ExprKind::Binary(ref op, ref left, ref right) = e.kind {
32+
if BinOpKind::Mul == op.node {
33+
match (&left.kind, &right.kind) {
34+
(&ExprKind::Unary(..), &ExprKind::Unary(..)) => {},
35+
(&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, right),
36+
(_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, left),
37+
_ => {},
38+
}
4439
}
4540
}
4641
}
@@ -49,14 +44,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
4944
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
5045
if_chain! {
5146
if let ExprKind::Lit(ref l) = lit.kind;
52-
if let Constant::Int(val) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
53-
if val == 1;
47+
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
5448
if cx.tables.expr_ty(exp).is_integral();
5549
then {
56-
span_lint(cx,
57-
NEG_MULTIPLY,
58-
span,
59-
"Negation by multiplying with -1");
50+
span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with -1");
6051
}
6152
}
6253
}

clippy_lints/src/transmuting_null.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
4848
if let ExprKind::Path(ref _qpath) = args[0].kind;
4949
let x = const_eval_context.expr(&args[0]);
5050
if let Some(constant) = x;
51-
if let Constant::RawPtr(ptr_value) = constant;
52-
if ptr_value == 0;
51+
if let Constant::RawPtr(0) = constant;
5352
then {
54-
span_lint(
55-
cx,
56-
TRANSMUTING_NULL,
57-
expr.span,
58-
LINT_MSG)
53+
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
5954
}
6055
}
6156

@@ -66,11 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
6661
if let ExprKind::Lit(ref lit) = inner_expr.kind;
6762
if let LitKind::Int(0, _) = lit.node;
6863
then {
69-
span_lint(
70-
cx,
71-
TRANSMUTING_NULL,
72-
expr.span,
73-
LINT_MSG)
64+
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
7465
}
7566
}
7667

@@ -82,11 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
8273
if match_qpath(path1, &paths::STD_PTR_NULL);
8374
if args1.len() == 0;
8475
then {
85-
span_lint(
86-
cx,
87-
TRANSMUTING_NULL,
88-
expr.span,
89-
LINT_MSG)
76+
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
9077
}
9178
}
9279

0 commit comments

Comments
 (0)