1 use clippy_utils::diagnostics::span_lint_and_sugg;
2 use rustc_ast::ast::{Pat, PatKind};
3 use rustc_errors::Applicability;
4 use rustc_lint::EarlyContext;
5 use rustc_span::source_map::Span;
7 use super::UNNEEDED_WILDCARD_PATTERN;
9 pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
10 if let PatKind::TupleStruct(_, _, ref patterns) | PatKind::Tuple(ref patterns) = pat.kind {
11 if let Some(rest_index) = patterns.iter().position(|pat| pat.is_rest()) {
12 if let Some((left_index, left_pat)) = patterns[..rest_index]
15 .take_while(|pat| matches!(pat.kind, PatKind::Wild))
19 span_lint(cx, left_pat.span.until(patterns[rest_index].span), left_index == 0);
22 if let Some((right_index, right_pat)) = patterns[rest_index + 1..]
24 .take_while(|pat| matches!(pat.kind, PatKind::Wild))
30 patterns[rest_index].span.shrink_to_hi().to(right_pat.span),
38 fn span_lint(cx: &EarlyContext<'_>, span: Span, only_one: bool) {
41 UNNEEDED_WILDCARD_PATTERN,
44 "this pattern is unneeded as the `..` pattern can match that element"
46 "these patterns are unneeded as the `..` pattern can match those elements"
48 if only_one { "remove it" } else { "remove them" },
50 Applicability::MachineApplicable,