mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 14:38:46 +00:00
Clean up some unused vars
This commit is contained in:
parent
b292183c68
commit
aa4f3fb537
4 changed files with 23 additions and 48 deletions
|
@ -48,14 +48,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) {
|
fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) {
|
||||||
if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
|
if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables, e) {
|
||||||
if v == 0 {
|
span_lint(
|
||||||
span_lint(
|
cx,
|
||||||
cx,
|
ERASING_OP,
|
||||||
ERASING_OP,
|
span,
|
||||||
span,
|
"this operation will always return zero. This is likely not the intended outcome",
|
||||||
"this operation will always return zero. This is likely not the intended outcome",
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
|
||||||
|
|
||||||
// RHS of subtraction is 1
|
// RHS of subtraction is 1
|
||||||
if let ExprKind::Lit(rhs_lit) = &rhs.kind;
|
if let ExprKind::Lit(rhs_lit) = &rhs.kind;
|
||||||
if let LitKind::Int(rhs_value, ..) = rhs_lit.node;
|
if let LitKind::Int(1, ..) = rhs_lit.node;
|
||||||
if rhs_value == 1;
|
|
||||||
|
|
||||||
then {
|
then {
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use if_chain::if_chain;
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
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::consts::{self, Constant};
|
||||||
use crate::utils::span_lint;
|
use crate::utils::span_lint;
|
||||||
|
@ -28,19 +28,14 @@ declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
|
||||||
#[allow(clippy::match_same_arms)]
|
#[allow(clippy::match_same_arms)]
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||||
if let ExprKind::Binary(
|
if let ExprKind::Binary(ref op, ref left, ref right) = e.kind {
|
||||||
Spanned {
|
if BinOpKind::Mul == op.node {
|
||||||
node: BinOpKind::Mul, ..
|
match (&left.kind, &right.kind) {
|
||||||
},
|
(&ExprKind::Unary(..), &ExprKind::Unary(..)) => {},
|
||||||
ref l,
|
(&ExprKind::Unary(UnNeg, ref lit), _) => check_mul(cx, e.span, lit, right),
|
||||||
ref r,
|
(_, &ExprKind::Unary(UnNeg, ref lit)) => check_mul(cx, e.span, lit, left),
|
||||||
) = 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),
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,14 +44,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
|
||||||
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
|
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Lit(ref l) = lit.kind;
|
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 let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
|
||||||
if val == 1;
|
|
||||||
if cx.tables.expr_ty(exp).is_integral();
|
if cx.tables.expr_ty(exp).is_integral();
|
||||||
then {
|
then {
|
||||||
span_lint(cx,
|
span_lint(cx, NEG_MULTIPLY, span, "Negation by multiplying with -1");
|
||||||
NEG_MULTIPLY,
|
|
||||||
span,
|
|
||||||
"Negation by multiplying with -1");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,14 +48,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
|
||||||
if let ExprKind::Path(ref _qpath) = args[0].kind;
|
if let ExprKind::Path(ref _qpath) = args[0].kind;
|
||||||
let x = const_eval_context.expr(&args[0]);
|
let x = const_eval_context.expr(&args[0]);
|
||||||
if let Some(constant) = x;
|
if let Some(constant) = x;
|
||||||
if let Constant::RawPtr(ptr_value) = constant;
|
if let Constant::RawPtr(0) = constant;
|
||||||
if ptr_value == 0;
|
|
||||||
then {
|
then {
|
||||||
span_lint(
|
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
|
||||||
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 ExprKind::Lit(ref lit) = inner_expr.kind;
|
||||||
if let LitKind::Int(0, _) = lit.node;
|
if let LitKind::Int(0, _) = lit.node;
|
||||||
then {
|
then {
|
||||||
span_lint(
|
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
|
||||||
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 match_qpath(path1, &paths::STD_PTR_NULL);
|
||||||
if args1.len() == 0;
|
if args1.len() == 0;
|
||||||
then {
|
then {
|
||||||
span_lint(
|
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
|
||||||
cx,
|
|
||||||
TRANSMUTING_NULL,
|
|
||||||
expr.span,
|
|
||||||
LINT_MSG)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue