Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 52cfde0

Browse files
committed
move redundant_pattern to its own module
1 parent 55af0ce commit 52cfde0

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

clippy_lints/src/misc_early/mod.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
mod builtin_type_shadow;
22
mod double_neg;
3+
mod redundant_pattern;
34

45
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
56
use clippy_utils::source::snippet_opt;
6-
use rustc_ast::ast::{
7-
BindingMode, Expr, Generics, Lit, LitFloatType, LitIntType, LitKind, Mutability, NodeId, Pat, PatKind,
8-
};
7+
use rustc_ast::ast::{Expr, Generics, Lit, LitFloatType, LitIntType, LitKind, NodeId, Pat, PatKind};
98
use rustc_ast::visit::FnKind;
109
use rustc_data_structures::fx::FxHashMap;
1110
use rustc_errors::Applicability;
@@ -336,29 +335,7 @@ impl EarlyLintPass for MiscEarlyLints {
336335
}
337336
}
338337

339-
if let PatKind::Ident(left, ident, Some(ref right)) = pat.kind {
340-
let left_binding = match left {
341-
BindingMode::ByRef(Mutability::Mut) => "ref mut ",
342-
BindingMode::ByRef(Mutability::Not) => "ref ",
343-
BindingMode::ByValue(..) => "",
344-
};
345-
346-
if let PatKind::Wild = right.kind {
347-
span_lint_and_sugg(
348-
cx,
349-
REDUNDANT_PATTERN,
350-
pat.span,
351-
&format!(
352-
"the `{} @ _` pattern can be written as just `{}`",
353-
ident.name, ident.name,
354-
),
355-
"try",
356-
format!("{}{}", left_binding, ident.name),
357-
Applicability::MachineApplicable,
358-
);
359-
}
360-
}
361-
338+
redundant_pattern::check(cx, pat);
362339
check_unneeded_wildcard_pattern(cx, pat);
363340
}
364341

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use rustc_ast::ast::{BindingMode, Mutability, 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(left, ident, Some(ref right)) = pat.kind {
10+
let left_binding = match left {
11+
BindingMode::ByRef(Mutability::Mut) => "ref mut ",
12+
BindingMode::ByRef(Mutability::Not) => "ref ",
13+
BindingMode::ByValue(..) => "",
14+
};
15+
16+
if let PatKind::Wild = right.kind {
17+
span_lint_and_sugg(
18+
cx,
19+
REDUNDANT_PATTERN,
20+
pat.span,
21+
&format!(
22+
"the `{} @ _` pattern can be written as just `{}`",
23+
ident.name, ident.name,
24+
),
25+
"try",
26+
format!("{}{}", left_binding, ident.name),
27+
Applicability::MachineApplicable,
28+
);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)