Skip to content

Commit ecfde6e

Browse files
committed
clean up code a bit
1 parent cb6579b commit ecfde6e

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

compiler/rustc_errors/src/emitter.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1748,16 +1748,11 @@ impl HumanEmitter {
17481748
let suggestions = suggestion.splice_lines(sm);
17491749
debug!(?suggestions);
17501750

1751-
if suggestions
1752-
.iter()
1751+
if suggestions.is_empty() {
17531752
// Here we check if there are suggestions that have actual code changes. We sometimes
17541753
// suggest the same code that is already there, instead of changing how we produce the
17551754
// suggestions and filtering there, we just don't emit the suggestion.
1756-
.filter(|(_, _, highlights, _)| !highlights.iter().all(|parts| parts.is_empty()))
1757-
.count()
1758-
== 0
1759-
{
1760-
// Suggestions coming from macros can have malformed spans. This is a heavy handed
1755+
// Suggestions coming from macros can also have malformed spans. This is a heavy handed
17611756
// approach to avoid ICEs by ignoring the suggestion outright.
17621757
return Ok(());
17631758
}
@@ -1771,7 +1766,6 @@ impl HumanEmitter {
17711766
let mut msg = vec![(suggestion.msg.to_owned(), Style::NoStyle)];
17721767
if suggestions
17731768
.iter()
1774-
.filter(|(_, _, highlights, _)| !highlights.is_empty())
17751769
.take(MAX_SUGGESTIONS)
17761770
.any(|(_, _, _, only_capitalization)| *only_capitalization)
17771771
{
@@ -1788,11 +1782,7 @@ impl HumanEmitter {
17881782

17891783
let mut row_num = 2;
17901784
draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
1791-
for (complete, parts, highlights, _) in suggestions
1792-
.iter()
1793-
.filter(|(_, _, highlights, _)| !highlights.is_empty())
1794-
.take(MAX_SUGGESTIONS)
1795-
{
1785+
for (complete, parts, highlights, _) in suggestions.iter().take(MAX_SUGGESTIONS) {
17961786
debug!(?complete, ?parts, ?highlights);
17971787

17981788
let has_deletion = parts.iter().any(|p| p.is_deletion(sm));

compiler/rustc_errors/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,11 @@ impl CodeSuggestion {
399399
while buf.ends_with('\n') {
400400
buf.pop();
401401
}
402-
Some((buf, substitution.parts, highlights, only_capitalization))
402+
if highlights.iter().all(|parts| parts.is_empty()) {
403+
None
404+
} else {
405+
Some((buf, substitution.parts, highlights, only_capitalization))
406+
}
403407
})
404408
.collect()
405409
}

0 commit comments

Comments
 (0)