diff options
| author | bors <bors@rust-lang.org> | 2023-09-05 12:01:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-05 12:01:31 +0000 |
| commit | eb0df1d4f4560fbfd6a97e6d1cf7668cbfc3e9c4 (patch) | |
| tree | 1d18b8c43cd44ccdd9cd6e74ff2d02a2c08c5c7b /clippy_lints/src/ignored_unit_patterns.rs | |
| parent | bcf856bfb3e025be69ff371e4439205445b76a00 (diff) | |
| parent | 2f5c445c0bea87315b5517fce83a2f5442a94bc4 (diff) | |
| download | rust-eb0df1d4f4560fbfd6a97e6d1cf7668cbfc3e9c4.tar.gz rust-eb0df1d4f4560fbfd6a97e6d1cf7668cbfc3e9c4.zip | |
Auto merge of #11454 - samueltardieu:issue-11403, r=Centri3
Ignore wildcards in function arguments and local bindings Fix #11403 changelog: none
Diffstat (limited to 'clippy_lints/src/ignored_unit_patterns.rs')
| -rw-r--r-- | clippy_lints/src/ignored_unit_patterns.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clippy_lints/src/ignored_unit_patterns.rs b/clippy_lints/src/ignored_unit_patterns.rs index c635120b882..d8ead1c9d9f 100644 --- a/clippy_lints/src/ignored_unit_patterns.rs +++ b/clippy_lints/src/ignored_unit_patterns.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use hir::PatKind; +use hir::{Node, PatKind}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; @@ -37,6 +37,17 @@ declare_lint_pass!(IgnoredUnitPatterns => [IGNORED_UNIT_PATTERNS]); impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns { fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) { + match cx.tcx.hir().get_parent(pat.hir_id) { + Node::Param(param) if matches!(cx.tcx.hir().get_parent(param.hir_id), Node::Item(_)) => { + // Ignore function parameters + return; + }, + Node::Local(local) if local.ty.is_some() => { + // Ignore let bindings with explicit type + return; + }, + _ => {}, + } if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).is_unit() { span_lint_and_sugg( cx, |
