Skip to content

Commit 1d57a66

Browse files
committed
Update clippy
1 parent b5567e5 commit 1d57a66

File tree

14 files changed

+66
-136
lines changed

14 files changed

+66
-136
lines changed

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
4848
if let Some(anon_const) = &var.disr_expr {
4949
let param_env = ty::ParamEnv::empty();
5050
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
51-
let substs = InternalSubsts::identity_for_item(cx.tcx.global_tcx(), def_id);
51+
let substs = InternalSubsts::identity_for_item(cx.tcx, def_id);
5252
let instance = ty::Instance::new(def_id, substs);
5353
let c_id = GlobalId {
5454
instance,

clippy_lints/src/erasing_op.rs

Lines changed: 7 additions & 9 deletions
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

Lines changed: 1 addition & 2 deletions
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/inherent_impl.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! lint on inherent implementations
22
3-
use crate::utils::span_lint_and_then;
3+
use crate::utils::{in_macro, span_lint_and_then};
44
use rustc::hir::*;
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::{declare_tool_lint, impl_lint_pass};
@@ -52,7 +52,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
5252
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.kind {
5353
// Remember for each inherent implementation encoutered its span and generics
5454
// but filter out implementations that have generic params (type or lifetime)
55-
if generics.params.len() == 0 {
55+
// or are derived from a macro
56+
if !in_macro(item.span) && generics.params.len() == 0 {
5657
self.impls.insert(item.hir_id.owner_def_id(), item.span);
5758
}
5859
}

clippy_lints/src/loops.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,21 @@ declare_lint_pass!(Loops => [
476476
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
477477
#[allow(clippy::too_many_lines)]
478478
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
479+
if let Some((pat, arg, body)) = higher::for_loop(expr) {
480+
// we don't want to check expanded macros
481+
// this check is not at the top of the function
482+
// since higher::for_loop expressions are marked as expansions
483+
if body.span.from_expansion() {
484+
return;
485+
}
486+
check_for_loop(cx, pat, arg, body, expr);
487+
}
488+
479489
// we don't want to check expanded macros
480490
if expr.span.from_expansion() {
481491
return;
482492
}
483493

484-
if let Some((pat, arg, body)) = higher::for_loop(expr) {
485-
check_for_loop(cx, pat, arg, body, expr);
486-
}
487-
488494
// check for never_loop
489495
if let ExprKind::Loop(ref block, _, _) = expr.kind {
490496
match never_loop_block(block, expr.hir_id) {
@@ -1039,10 +1045,6 @@ fn check_for_loop_range<'a, 'tcx>(
10391045
body: &'tcx Expr,
10401046
expr: &'tcx Expr,
10411047
) {
1042-
if expr.span.from_expansion() {
1043-
return;
1044-
}
1045-
10461048
if let Some(higher::Range {
10471049
start: Some(start),
10481050
ref end,

clippy_lints/src/neg_multiply.rs

Lines changed: 11 additions & 20 deletions
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

Lines changed: 4 additions & 17 deletions
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

clippy_lints/src/utils/hir_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
669669
TyKind::Typeof(anon_const) => {
670670
self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value);
671671
},
672-
TyKind::CVarArgs(lifetime) => self.hash_lifetime(lifetime),
673672
TyKind::Err | TyKind::Infer | TyKind::Never => {},
674673
}
675674
}

clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ pub fn type_is_unsafe_function<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx
799799
}
800800

801801
pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
802-
ty.is_copy_modulo_regions(cx.tcx.global_tcx(), cx.param_env, DUMMY_SP)
802+
ty.is_copy_modulo_regions(cx.tcx, cx.param_env, DUMMY_SP)
803803
}
804804

805805
/// Checks if an expression is constructing a tuple-like enum variant or struct

tests/ui/crashes/inherent_impl.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![deny(clippy::multiple_inherent_impl)]
2+
3+
/// Test for https://github.com/rust-lang/rust-clippy/issues/4578
4+
5+
macro_rules! impl_foo {
6+
($struct:ident) => {
7+
impl $struct {
8+
fn foo() {}
9+
}
10+
};
11+
}
12+
13+
macro_rules! impl_bar {
14+
($struct:ident) => {
15+
impl $struct {
16+
fn bar() {}
17+
}
18+
};
19+
}
20+
21+
struct MyStruct;
22+
23+
impl_foo!(MyStruct);
24+
impl_bar!(MyStruct);
25+
26+
fn main() {}

0 commit comments

Comments
 (0)