Skip to content

Commit 4935e02

Browse files
committed
1 parent b0c4744 commit 4935e02

File tree

109 files changed

+735
-655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+735
-655
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
6060
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
6161

6262
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
63-
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
63+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
6464
if let ExprKind::Lit(lit) = &e.kind {
6565
check_lit(cx, &lit.node, e);
6666
}
6767
}
6868
}
6969

70-
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
70+
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr<'_>) {
7171
match *lit {
7272
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
7373
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
@@ -78,7 +78,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
7878
}
7979
}
8080

81-
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
81+
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) {
8282
let s = s.as_str();
8383
if s.parse::<f64>().is_ok() {
8484
for &(constant, name, min_digits) in &KNOWN_CONSTS {

clippy_lints/src/arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct Arithmetic {
5454
impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
5555

5656
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
57-
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
57+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
5858
if self.expr_span.is_some() {
5959
return;
6060
}
@@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
107107
}
108108
}
109109

110-
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
110+
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
111111
if Some(expr.span) == self.expr_span {
112112
self.expr_span = None;
113113
}

clippy_lints/src/assertions_on_constants.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare_clippy_lint! {
3333
declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3434

3535
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
36-
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
36+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
3737
let lint_true = || {
3838
span_help_and_lint(
3939
cx,
@@ -110,7 +110,7 @@ enum AssertKind {
110110
/// ```
111111
///
112112
/// where `message` is any expression and `c` is a constant bool.
113-
fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<AssertKind> {
113+
fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
114114
if_chain! {
115115
if let ExprKind::Match(ref expr, ref arms, _) = expr.kind;
116116
// matches { let _t = expr; _t }
@@ -124,7 +124,7 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E
124124
if let LitKind::Bool(true) = lit.node;
125125
// arm 1 block
126126
if let ExprKind::Block(ref block, _) = arms[0].body.kind;
127-
if block.stmts.len() == 0;
127+
if block.stmts.is_empty();
128128
if let Some(block_expr) = &block.expr;
129129
if let ExprKind::Block(ref inner_block, _) = block_expr.kind;
130130
if let Some(begin_panic_call) = &inner_block.expr;

clippy_lints/src/assign_ops.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
5959

6060
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
6161
#[allow(clippy::too_many_lines)]
62-
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
62+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
6363
match &expr.kind {
6464
hir::ExprKind::AssignOp(op, lhs, rhs) => {
6565
if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind {
@@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7979
hir::ExprKind::Assign(assignee, e, _) => {
8080
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
8181
#[allow(clippy::cognitive_complexity)]
82-
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
82+
let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| {
8383
let ty = cx.tables.expr_ty(assignee);
8484
let rty = cx.tables.expr_ty(rhs);
8585
macro_rules! ops {
@@ -190,11 +190,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
190190

191191
fn lint_misrefactored_assign_op(
192192
cx: &LateContext<'_, '_>,
193-
expr: &hir::Expr,
193+
expr: &hir::Expr<'_>,
194194
op: hir::BinOp,
195-
rhs: &hir::Expr,
196-
assignee: &hir::Expr,
197-
rhs_other: &hir::Expr,
195+
rhs: &hir::Expr<'_>,
196+
assignee: &hir::Expr<'_>,
197+
rhs_other: &hir::Expr<'_>,
198198
) {
199199
span_lint_and_then(
200200
cx,
@@ -240,13 +240,13 @@ fn is_commutative(op: hir::BinOpKind) -> bool {
240240
}
241241

242242
struct ExprVisitor<'a, 'tcx> {
243-
assignee: &'a hir::Expr,
243+
assignee: &'a hir::Expr<'a>,
244244
counter: u8,
245245
cx: &'a LateContext<'a, 'tcx>,
246246
}
247247

248248
impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
249-
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
249+
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
250250
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) {
251251
self.counter += 1;
252252
}

clippy_lints/src/attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool {
380380
}
381381
}
382382

383-
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
383+
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool {
384384
if let Some(stmt) = block.stmts.first() {
385385
match &stmt.kind {
386386
StmtKind::Local(_) => true,
@@ -392,7 +392,7 @@ fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, bl
392392
}
393393
}
394394

395-
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
395+
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool {
396396
match &expr.kind {
397397
ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
398398
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),

clippy_lints/src/bit_mask.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl BitMask {
112112
impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]);
113113

114114
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
115-
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
115+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
116116
if let ExprKind::Binary(cmp, left, right) = &e.kind {
117117
if cmp.node.is_comparison() {
118118
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
@@ -165,7 +165,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
165165
}
166166
}
167167

168-
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
168+
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
169169
if let ExprKind::Binary(op, left, right) = &bit_op.kind {
170170
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
171171
return;
@@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128,
319319
}
320320
}
321321

322-
fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr) -> Option<u128> {
322+
fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr<'_>) -> Option<u128> {
323323
match constant(cx, cx.tables, lit)?.0 {
324324
Constant::Int(n) => Some(n),
325325
_ => None,

clippy_lints/src/blacklisted_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl BlacklistedName {
3737
impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
3838

3939
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName {
40-
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
40+
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) {
4141
if let PatKind::Binding(.., ident, _) = pat.kind {
4242
if self.blacklist.contains(&ident.name.to_string()) {
4343
span_lint(

clippy_lints/src/block_in_if_condition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ declare_clippy_lint! {
4646
declare_lint_pass!(BlockInIfCondition => [BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT]);
4747

4848
struct ExVisitor<'a, 'tcx> {
49-
found_block: Option<&'tcx Expr>,
49+
found_block: Option<&'tcx Expr<'tcx>>,
5050
cx: &'a LateContext<'a, 'tcx>,
5151
}
5252

5353
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
54-
fn visit_expr(&mut self, expr: &'tcx Expr) {
54+
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
5555
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
5656
let body = self.cx.tcx.hir().body(eid);
5757
let ex = &body.value;
@@ -72,7 +72,7 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks
7272
instead, move the block or closure higher and bind it with a 'let'";
7373

7474
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
75-
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
75+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
7676
if in_external_macro(cx.sess(), expr.span) {
7777
return;
7878
}

clippy_lints/src/booleans.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ struct NonminimalBoolVisitor<'a, 'tcx> {
7575

7676
use quine_mc_cluskey::Bool;
7777
struct Hir2Qmm<'a, 'tcx, 'v> {
78-
terminals: Vec<&'v Expr>,
78+
terminals: Vec<&'v Expr<'v>>,
7979
cx: &'a LateContext<'a, 'tcx>,
8080
}
8181

8282
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
83-
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
83+
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr<'_>], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
8484
for a in a {
8585
if let ExprKind::Binary(binop, lhs, rhs) = &a.kind {
8686
if binop.node == op {
@@ -93,7 +93,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
9393
Ok(v)
9494
}
9595

96-
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
96+
fn run(&mut self, e: &'v Expr<'_>) -> Result<Bool, String> {
9797
fn negate(bin_op_kind: BinOpKind) -> Option<BinOpKind> {
9898
match bin_op_kind {
9999
BinOpKind::Eq => Some(BinOpKind::Ne),
@@ -154,7 +154,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
154154
}
155155

156156
struct SuggestContext<'a, 'tcx, 'v> {
157-
terminals: &'v [&'v Expr],
157+
terminals: &'v [&'v Expr<'v>],
158158
cx: &'a LateContext<'a, 'tcx>,
159159
output: String,
160160
}
@@ -222,7 +222,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
222222
}
223223
}
224224

225-
fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
225+
fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<String> {
226226
match &expr.kind {
227227
ExprKind::Binary(binop, lhs, rhs) => {
228228
if !implements_ord(cx, lhs) {
@@ -266,7 +266,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
266266
}
267267
}
268268

269-
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> String {
269+
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
270270
let mut suggest_context = SuggestContext {
271271
terminals,
272272
cx,
@@ -332,7 +332,7 @@ fn terminal_stats(b: &Bool) -> Stats {
332332
}
333333

334334
impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
335-
fn bool_expr(&self, e: &'tcx Expr) {
335+
fn bool_expr(&self, e: &'tcx Expr<'_>) {
336336
let mut h2q = Hir2Qmm {
337337
terminals: Vec::new(),
338338
cx: self.cx,
@@ -437,7 +437,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
437437
}
438438

439439
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
440-
fn visit_expr(&mut self, e: &'tcx Expr) {
440+
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
441441
if in_macro(e.span) {
442442
return;
443443
}
@@ -460,7 +460,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
460460
}
461461
}
462462

463-
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> bool {
463+
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
464464
let ty = cx.tables.expr_ty(expr);
465465
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
466466
}
@@ -470,7 +470,7 @@ struct NotSimplificationVisitor<'a, 'tcx> {
470470
}
471471

472472
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
473-
fn visit_expr(&mut self, expr: &'tcx Expr) {
473+
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
474474
if let ExprKind::Unary(UnNot, inner) = &expr.kind {
475475
if let Some(suggestion) = simplify_not(self.cx, inner) {
476476
span_lint_and_sugg(

clippy_lints/src/bytecount.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare_clippy_lint! {
3636
declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
3737

3838
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
39-
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
39+
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
4040
if_chain! {
4141
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.kind;
4242
if count.ident.name == sym!(count);
@@ -96,11 +96,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
9696
}
9797
}
9898

99-
fn check_arg(name: Name, arg: Name, needle: &Expr) -> bool {
99+
fn check_arg(name: Name, arg: Name, needle: &Expr<'_>) -> bool {
100100
name == arg && !contains_name(name, needle)
101101
}
102102

103-
fn get_path_name(expr: &Expr) -> Option<Name> {
103+
fn get_path_name(expr: &Expr<'_>) -> Option<Name> {
104104
match expr.kind {
105105
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => {
106106
get_path_name(e)

0 commit comments

Comments
 (0)