Skip to content

Commit

Permalink
Auto merge of #4601 - lzutao:clean-up-unused-vars, r=phansch
Browse files Browse the repository at this point in the history
Clean up some unused vars

changelog: none
  • Loading branch information
bors committed Sep 29, 2019
2 parents b292183 + aa4f3fb commit 406e89a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 48 deletions.
16 changes: 7 additions & 9 deletions clippy_lints/src/erasing_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
}

fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) {
if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
if v == 0 {
span_lint(
cx,
ERASING_OP,
span,
"this operation will always return zero. This is likely not the intended outcome",
);
}
if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) {
span_lint(
cx,
ERASING_OP,
span,
"this operation will always return zero. This is likely not the intended outcome",
);
}
}
3 changes: 1 addition & 2 deletions clippy_lints/src/get_last_with_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {

// RHS of subtraction is 1
if let ExprKind::Lit(rhs_lit) = &rhs.kind;
if let LitKind::Int(rhs_value, ..) = rhs_lit.node;
if rhs_value == 1;
if let LitKind::Int(1, ..) = rhs_lit.node;

then {
let mut applicability = Applicability::MachineApplicable;
Expand Down
31 changes: 11 additions & 20 deletions clippy_lints/src/neg_multiply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use if_chain::if_chain;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::source_map::{Span, Spanned};
use syntax::source_map::Span;

use crate::consts::{self, Constant};
use crate::utils::span_lint;
Expand All @@ -28,19 +28,14 @@ declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
#[allow(clippy::match_same_arms)]
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Binary(
Spanned {
node: BinOpKind::Mul, ..
},
ref l,
ref r,
) = e.kind
{
match (&l.kind, &r.kind) {
(&ExprKind::Unary(..), &ExprKind::Unary(..)) => (),
(&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, r),
(_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, l),
_ => (),
if let ExprKind::Binary(ref op, ref left, ref right) = e.kind {
if BinOpKind::Mul == op.node {
match (&left.kind, &right.kind) {
(&ExprKind::Unary(..), &ExprKind::Unary(..)) => {},
(&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, right),
(_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, left),
_ => {},
}
}
}
}
Expand All @@ -49,14 +44,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
if_chain! {
if let ExprKind::Lit(ref l) = lit.kind;
if let Constant::Int(val) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
if val == 1;
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
if cx.tables.expr_ty(exp).is_integral();
then {
span_lint(cx,
NEG_MULTIPLY,
span,
"Negation by multiplying with -1");
span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with -1");
}
}
}
21 changes: 4 additions & 17 deletions clippy_lints/src/transmuting_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
if let ExprKind::Path(ref _qpath) = args[0].kind;
let x = const_eval_context.expr(&args[0]);
if let Some(constant) = x;
if let Constant::RawPtr(ptr_value) = constant;
if ptr_value == 0;
if let Constant::RawPtr(0) = constant;
then {
span_lint(
cx,
TRANSMUTING_NULL,
expr.span,
LINT_MSG)
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
}
}

Expand All @@ -66,11 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
if let ExprKind::Lit(ref lit) = inner_expr.kind;
if let LitKind::Int(0, _) = lit.node;
then {
span_lint(
cx,
TRANSMUTING_NULL,
expr.span,
LINT_MSG)
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
}
}

Expand All @@ -82,11 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
if match_qpath(path1, &paths::STD_PTR_NULL);
if args1.len() == 0;
then {
span_lint(
cx,
TRANSMUTING_NULL,
expr.span,
LINT_MSG)
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
}
}

Expand Down

0 comments on commit 406e89a

Please sign in to comment.