diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2020-03-08 02:50:33 +0100 |
|---|---|---|
| committer | Matthias Krüger <matthias.krueger@famsik.de> | 2020-03-08 02:50:33 +0100 |
| commit | a412b3423e99c2cf0841ffc2f406322b1b0c9c29 (patch) | |
| tree | 0e0c93100241238ba1d4a03fd346fca261e4f624 | |
| parent | 3d0f0e33aff4f5d916ec286bc586935d767c3cfc (diff) | |
| download | rust-a412b3423e99c2cf0841ffc2f406322b1b0c9c29.tar.gz rust-a412b3423e99c2cf0841ffc2f406322b1b0c9c29.zip | |
check_pat: delay creation of the "normal" vec until we reach the branch where is is actually needed
| -rw-r--r-- | clippy_lints/src/misc_early.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 60b67276623..28fdb3d015e 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -318,18 +318,6 @@ impl EarlyLintPass for MiscEarlyLints { return; } if wilds > 0 { - let mut normal = vec![]; - - for field in pfields { - match field.pat.kind { - PatKind::Wild => {}, - _ => { - if let Ok(n) = cx.sess().source_map().span_to_snippet(field.span) { - normal.push(n); - } - }, - } - } for field in pfields { if let PatKind::Wild = field.pat.kind { wilds -= 1; @@ -341,6 +329,19 @@ impl EarlyLintPass for MiscEarlyLints { "You matched a field with a wildcard pattern. Consider using `..` instead", ); } else { + let mut normal = vec![]; + + for field in pfields { + match field.pat.kind { + PatKind::Wild => {}, + _ => { + if let Ok(n) = cx.sess().source_map().span_to_snippet(field.span) { + normal.push(n); + } + }, + } + } + span_lint_and_help( cx, UNNEEDED_FIELD_PATTERN, |
