|
1 | 1 | mod builtin_type_shadow;
|
2 | 2 | mod double_neg;
|
3 | 3 | mod redundant_pattern;
|
| 4 | +mod unneeded_wildcard_pattern; |
4 | 5 |
|
5 | 6 | use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
|
6 | 7 | use clippy_utils::source::snippet_opt;
|
@@ -336,7 +337,7 @@ impl EarlyLintPass for MiscEarlyLints {
|
336 | 337 | }
|
337 | 338 |
|
338 | 339 | redundant_pattern::check(cx, pat);
|
339 |
| - check_unneeded_wildcard_pattern(cx, pat); |
| 340 | + unneeded_wildcard_pattern::check(cx, pat); |
340 | 341 | }
|
341 | 342 |
|
342 | 343 | fn check_fn(&mut self, cx: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
|
@@ -478,48 +479,3 @@ impl MiscEarlyLints {
|
478 | 479 | }
|
479 | 480 | }
|
480 | 481 | }
|
481 |
| - |
482 |
| -fn check_unneeded_wildcard_pattern(cx: &EarlyContext<'_>, pat: &Pat) { |
483 |
| - if let PatKind::TupleStruct(_, ref patterns) | PatKind::Tuple(ref patterns) = pat.kind { |
484 |
| - fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) { |
485 |
| - span_lint_and_sugg( |
486 |
| - cx, |
487 |
| - UNNEEDED_WILDCARD_PATTERN, |
488 |
| - span, |
489 |
| - if only_one { |
490 |
| - "this pattern is unneeded as the `..` pattern can match that element" |
491 |
| - } else { |
492 |
| - "these patterns are unneeded as the `..` pattern can match those elements" |
493 |
| - }, |
494 |
| - if only_one { "remove it" } else { "remove them" }, |
495 |
| - "".to_string(), |
496 |
| - Applicability::MachineApplicable, |
497 |
| - ); |
498 |
| - } |
499 |
| - |
500 |
| - if let Some(rest_index) = patterns.iter().position(|pat| pat.is_rest()) { |
501 |
| - if let Some((left_index, left_pat)) = patterns[..rest_index] |
502 |
| - .iter() |
503 |
| - .rev() |
504 |
| - .take_while(|pat| matches!(pat.kind, PatKind::Wild)) |
505 |
| - .enumerate() |
506 |
| - .last() |
507 |
| - { |
508 |
| - span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0); |
509 |
| - } |
510 |
| - |
511 |
| - if let Some((right_index, right_pat)) = patterns[rest_index + 1..] |
512 |
| - .iter() |
513 |
| - .take_while(|pat| matches!(pat.kind, PatKind::Wild)) |
514 |
| - .enumerate() |
515 |
| - .last() |
516 |
| - { |
517 |
| - span_lint( |
518 |
| - cx, |
519 |
| - patterns[rest_index].span.shrink_to_hi().to(right_pat.span), |
520 |
| - right_index == 0, |
521 |
| - ); |
522 |
| - } |
523 |
| - } |
524 |
| - } |
525 |
| -} |
0 commit comments