ignored_unit_patterns: Reorder checks.

This commit is contained in:
Jason Newcomb 2024-06-11 14:59:36 -04:00
parent 517e1ac225
commit 3869e93408

View File

@ -37,22 +37,21 @@ declare_lint_pass!(IgnoredUnitPatterns => [IGNORED_UNIT_PATTERNS]);
impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns { impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) { fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
if pat.span.from_expansion() { if matches!(pat.kind, PatKind::Wild)
return; && !pat.span.from_expansion()
} && cx.typeck_results().pat_ty(pat).peel_refs().is_unit()
{
match cx.tcx.parent_hir_node(pat.hir_id) { match cx.tcx.parent_hir_node(pat.hir_id) {
Node::Param(param) if matches!(cx.tcx.parent_hir_node(param.hir_id), Node::Item(_)) => { Node::Param(param) if matches!(cx.tcx.parent_hir_node(param.hir_id), Node::Item(_)) => {
// Ignore function parameters // Ignore function parameters
return; return;
}, },
Node::LetStmt(local) if local.ty.is_some() => { Node::LetStmt(local) if local.ty.is_some() => {
// Ignore let bindings with explicit type // Ignore let bindings with explicit type
return; return;
}, },
_ => {}, _ => {},
} }
if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).peel_refs().is_unit() {
span_lint_and_sugg( span_lint_and_sugg(
cx, cx,
IGNORED_UNIT_PATTERNS, IGNORED_UNIT_PATTERNS,