Skip to content

Commit aea2e39

Browse files
committed
clean up code a bit
1 parent 88c948e commit aea2e39

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
@@ -1773,16 +1773,11 @@ impl HumanEmitter {
17731773
let suggestions = suggestion.splice_lines(sm);
17741774
debug!(?suggestions);
17751775

1776-
if suggestions
1777-
.iter()
1776+
if suggestions.is_empty() {
17781777
// Here we check if there are suggestions that have actual code changes. We sometimes
17791778
// suggest the same code that is already there, instead of changing how we produce the
17801779
// suggestions and filtering there, we just don't emit the suggestion.
1781-
.filter(|(_, _, highlights, _)| !highlights.iter().all(|parts| parts.is_empty()))
1782-
.count()
1783-
== 0
1784-
{
1785-
// Suggestions coming from macros can have malformed spans. This is a heavy handed
1780+
// Suggestions coming from macros can also have malformed spans. This is a heavy handed
17861781
// approach to avoid ICEs by ignoring the suggestion outright.
17871782
return Ok(());
17881783
}
@@ -1796,7 +1791,6 @@ impl HumanEmitter {
17961791
let mut msg = vec![(suggestion.msg.to_owned(), Style::NoStyle)];
17971792
if suggestions
17981793
.iter()
1799-
.filter(|(_, _, highlights, _)| !highlights.is_empty())
18001794
.take(MAX_SUGGESTIONS)
18011795
.any(|(_, _, _, only_capitalization)| *only_capitalization)
18021796
{
@@ -1813,11 +1807,7 @@ impl HumanEmitter {
18131807

18141808
let mut row_num = 2;
18151809
draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
1816-
for (complete, parts, highlights, _) in suggestions
1817-
.iter()
1818-
.filter(|(_, _, highlights, _)| !highlights.is_empty())
1819-
.take(MAX_SUGGESTIONS)
1820-
{
1810+
for (complete, parts, highlights, _) in suggestions.iter().take(MAX_SUGGESTIONS) {
18211811
debug!(?complete, ?parts, ?highlights);
18221812

18231813
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
@@ -400,7 +400,11 @@ impl CodeSuggestion {
400400
while buf.ends_with('\n') {
401401
buf.pop();
402402
}
403-
Some((buf, substitution.parts, highlights, only_capitalization))
403+
if highlights.iter().all(|parts| parts.is_empty()) {
404+
None
405+
} else {
406+
Some((buf, substitution.parts, highlights, only_capitalization))
407+
}
404408
})
405409
.collect()
406410
}

0 commit comments

Comments
 (0)