Skip to content

Commit

Permalink
Auto merge of rust-lang#5286 - matthiaskrgr:delay_vec_creation, r=fli…
Browse files Browse the repository at this point in the history
…p1995

check_pat: delay creation of the "normal" vec until we reach the branch where it is actually needed

changelog: none
  • Loading branch information
bors committed Mar 9, 2020
2 parents 118594f + a412b34 commit 92e25bb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions clippy_lints/src/misc_early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 92e25bb

Please sign in to comment.