From aea2e39ef9e35dee821b3b3ef4f66c269f9bcf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 23 Jun 2024 17:23:53 +0000 Subject: [PATCH] clean up code a bit --- compiler/rustc_errors/src/emitter.rs | 16 +++------------- compiler/rustc_errors/src/lib.rs | 6 +++++- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index b7b5c7d03923..90abebe88d1a 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1773,16 +1773,11 @@ impl HumanEmitter { let suggestions = suggestion.splice_lines(sm); debug!(?suggestions); - if suggestions - .iter() + if suggestions.is_empty() { // Here we check if there are suggestions that have actual code changes. We sometimes // suggest the same code that is already there, instead of changing how we produce the // suggestions and filtering there, we just don't emit the suggestion. - .filter(|(_, _, highlights, _)| !highlights.iter().all(|parts| parts.is_empty())) - .count() - == 0 - { - // Suggestions coming from macros can have malformed spans. This is a heavy handed + // Suggestions coming from macros can also have malformed spans. This is a heavy handed // approach to avoid ICEs by ignoring the suggestion outright. return Ok(()); } @@ -1796,7 +1791,6 @@ impl HumanEmitter { let mut msg = vec![(suggestion.msg.to_owned(), Style::NoStyle)]; if suggestions .iter() - .filter(|(_, _, highlights, _)| !highlights.is_empty()) .take(MAX_SUGGESTIONS) .any(|(_, _, _, only_capitalization)| *only_capitalization) { @@ -1813,11 +1807,7 @@ impl HumanEmitter { let mut row_num = 2; draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1); - for (complete, parts, highlights, _) in suggestions - .iter() - .filter(|(_, _, highlights, _)| !highlights.is_empty()) - .take(MAX_SUGGESTIONS) - { + for (complete, parts, highlights, _) in suggestions.iter().take(MAX_SUGGESTIONS) { debug!(?complete, ?parts, ?highlights); let has_deletion = parts.iter().any(|p| p.is_deletion(sm)); diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 51666c01376c..06bba1acb9fd 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -400,7 +400,11 @@ impl CodeSuggestion { while buf.ends_with('\n') { buf.pop(); } - Some((buf, substitution.parts, highlights, only_capitalization)) + if highlights.iter().all(|parts| parts.is_empty()) { + None + } else { + Some((buf, substitution.parts, highlights, only_capitalization)) + } }) .collect() }