]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/misc_early/redundant_pattern.rs
Rollup merge of #104112 - yancyribbens:add-copy-to-repeat-description, r=JohnTitor
[rust.git] / src / tools / clippy / clippy_lints / src / misc_early / redundant_pattern.rs
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
6 use super::REDUNDANT_PATTERN;
7
8 pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
9     if let PatKind::Ident(ann, ident, Some(ref right)) = pat.kind {
10         if let PatKind::Wild = right.kind {
11             span_lint_and_sugg(
12                 cx,
13                 REDUNDANT_PATTERN,
14                 pat.span,
15                 &format!(
16                     "the `{} @ _` pattern can be written as just `{}`",
17                     ident.name, ident.name,
18                 ),
19                 "try",
20                 format!("{}{}", ann.prefix_str(), ident.name),
21                 Applicability::MachineApplicable,
22             );
23         }
24     }
25 }