Auto merge of #4601 - lzutao:clean-up-unused-vars, r=phansch

Clean up some unused vars

changelog: none
This commit is contained in:
bors 2019-09-29 17:05:36 +00:00
commit 406e89a00c
4 changed files with 23 additions and 48 deletions

View file

@ -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",
);
}
}

View file

@ -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;

View file

@ -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;
@ -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),
_ => {},
}
}
}
}
@ -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");
}
}
}

View file

@ -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)
}
}
@ -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)
}
}
@ -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)
}
}