From a412b3423e99c2cf0841ffc2f406322b1b0c9c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 8 Mar 2020 02:50:33 +0100 Subject: [PATCH] check_pat: delay creation of the "normal" vec until we reach the branch where is is actually needed --- clippy_lints/src/misc_early.rs | 25 +++++++++++++------------ 1 file 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,