Skip to content

Commit

Permalink
clean up code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jul 11, 2024
1 parent 88c948e commit aea2e39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
16 changes: 3 additions & 13 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand All @@ -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)
{
Expand All @@ -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));
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit aea2e39

Please sign in to comment.