Skip to content

Commit 00ca42f

Browse files
author
Michael Wright
committed
Fix lint warnings
1 parent 4a3bc6b commit 00ca42f

File tree

4 files changed

+63
-58
lines changed

4 files changed

+63
-58
lines changed

clippy_lints/src/eval_order_dependence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct DivergenceVisitor<'a, 'tcx> {
101101
impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
102102
fn maybe_walk_expr(&mut self, e: &'tcx Expr) {
103103
match e.node {
104-
ExprKind::Closure(.., _) => {},
104+
ExprKind::Closure(..) => {},
105105
ExprKind::Match(ref e, ref arms, _) => {
106106
self.visit_expr(e);
107107
for arm in arms {

clippy_lints/src/misc_early.rs

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -362,61 +362,7 @@ impl EarlyLintPass for MiscEarlyLints {
362362
}
363363
}
364364

365-
if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.node {
366-
fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) {
367-
span_lint_and_sugg(
368-
cx,
369-
UNNEEDED_WILDCARD_PATTERN,
370-
span,
371-
if only_one {
372-
"this pattern is unneeded as the `..` pattern can match that element"
373-
} else {
374-
"these patterns are unneeded as the `..` pattern can match those elements"
375-
},
376-
if only_one { "remove it" } else { "remove them" },
377-
"".to_string(),
378-
Applicability::MachineApplicable,
379-
);
380-
}
381-
382-
fn is_rest<P: std::ops::Deref<Target = Pat>>(pat: &P) -> bool {
383-
if let PatKind::Rest = pat.node {
384-
true
385-
} else {
386-
false
387-
}
388-
}
389-
390-
fn is_wild<P: std::ops::Deref<Target = Pat>>(pat: &&P) -> bool {
391-
if let PatKind::Wild = pat.node {
392-
true
393-
} else {
394-
false
395-
}
396-
}
397-
398-
if let Some(rest_index) = patterns.iter().position(is_rest) {
399-
if let Some((left_index, left_pat)) = patterns[..rest_index]
400-
.iter()
401-
.rev()
402-
.take_while(is_wild)
403-
.enumerate()
404-
.last()
405-
{
406-
span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0);
407-
}
408-
409-
if let Some((right_index, right_pat)) =
410-
patterns[rest_index + 1..].iter().take_while(is_wild).enumerate().last()
411-
{
412-
span_lint(
413-
cx,
414-
patterns[rest_index].span.shrink_to_hi().to(right_pat.span),
415-
right_index == 0,
416-
);
417-
}
418-
}
419-
}
365+
check_unneeded_wildcard_pattern(cx, pat);
420366
}
421367

422368
fn check_fn(&mut self, cx: &EarlyContext<'_>, _: FnKind<'_>, decl: &FnDecl, _: Span, _: NodeId) {
@@ -611,3 +557,62 @@ impl MiscEarlyLints {
611557
}
612558
}
613559
}
560+
561+
fn check_unneeded_wildcard_pattern(cx: &EarlyContext<'_>, pat: &Pat) {
562+
if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.node {
563+
fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) {
564+
span_lint_and_sugg(
565+
cx,
566+
UNNEEDED_WILDCARD_PATTERN,
567+
span,
568+
if only_one {
569+
"this pattern is unneeded as the `..` pattern can match that element"
570+
} else {
571+
"these patterns are unneeded as the `..` pattern can match those elements"
572+
},
573+
if only_one { "remove it" } else { "remove them" },
574+
"".to_string(),
575+
Applicability::MachineApplicable,
576+
);
577+
}
578+
579+
fn is_rest<P: std::ops::Deref<Target = Pat>>(pat: &P) -> bool {
580+
if let PatKind::Rest = pat.node {
581+
true
582+
} else {
583+
false
584+
}
585+
}
586+
587+
#[allow(clippy::trivially_copy_pass_by_ref)]
588+
fn is_wild<P: std::ops::Deref<Target = Pat>>(pat: &&P) -> bool {
589+
if let PatKind::Wild = pat.node {
590+
true
591+
} else {
592+
false
593+
}
594+
}
595+
596+
if let Some(rest_index) = patterns.iter().position(is_rest) {
597+
if let Some((left_index, left_pat)) = patterns[..rest_index]
598+
.iter()
599+
.rev()
600+
.take_while(is_wild)
601+
.enumerate()
602+
.last()
603+
{
604+
span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0);
605+
}
606+
607+
if let Some((right_index, right_pat)) =
608+
patterns[rest_index + 1..].iter().take_while(is_wild).enumerate().last()
609+
{
610+
span_lint(
611+
cx,
612+
patterns[rest_index].span.shrink_to_hi().to(right_pat.span),
613+
right_index == 0,
614+
);
615+
}
616+
}
617+
}
618+
}

clippy_lints/src/no_effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
4747
return false;
4848
}
4949
match expr.node {
50-
ExprKind::Lit(..) | ExprKind::Closure(.., _) => true,
50+
ExprKind::Lit(..) | ExprKind::Closure(..) => true,
5151
ExprKind::Path(..) => !has_drop(cx, cx.tables.expr_ty(expr)),
5252
ExprKind::Index(ref a, ref b) | ExprKind::Binary(_, ref a, ref b) => {
5353
has_no_effect(cx, a) && has_no_effect(cx, b)

clippy_lints/src/utils/sugg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'a> Sugg<'a> {
9393
match expr.node {
9494
hir::ExprKind::AddrOf(..)
9595
| hir::ExprKind::Box(..)
96-
| hir::ExprKind::Closure(.., _)
96+
| hir::ExprKind::Closure(..)
9797
| hir::ExprKind::Unary(..)
9898
| hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet),
9999
hir::ExprKind::Continue(..)

0 commit comments

Comments
 (0)