Skip to content

Commit b0a99fd

Browse files
estebankMark-Simulacrum
authored andcommitted
review comments
1 parent 356ff77 commit b0a99fd

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/librustc_errors/emitter.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,11 @@ impl EmitterWriter {
14771477
Some(ref sm) => sm,
14781478
None => return Ok(()),
14791479
};
1480-
if !suggestion.has_valid_spans(&**sm) {
1480+
1481+
// Render the replacements for each suggestion
1482+
let suggestions = suggestion.splice_lines(&**sm);
1483+
1484+
if suggestions.is_empty() {
14811485
// Suggestions coming from macros can have malformed spans. This is a heavy handed
14821486
// approach to avoid ICEs by ignoring the suggestion outright.
14831487
return Ok(());
@@ -1499,9 +1503,6 @@ impl EmitterWriter {
14991503
Some(Style::HeaderMsg),
15001504
);
15011505

1502-
// Render the replacements for each suggestion
1503-
let suggestions = suggestion.splice_lines(&**sm);
1504-
15051506
let mut row_num = 2;
15061507
let mut notice_capitalization = false;
15071508
for (complete, parts, only_capitalization) in suggestions.iter().take(MAX_SUGGESTIONS) {

src/librustc_errors/lib.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,6 @@ pub struct SubstitutionPart {
144144
}
145145

146146
impl CodeSuggestion {
147-
/// Suggestions coming from macros can have malformed spans. This is a heavy handed approach
148-
/// to avoid ICEs by ignoring the suggestion outright.
149-
pub fn has_valid_spans(&self, cm: &SourceMap) -> bool {
150-
!self.substitutions.iter().any(|subst| {
151-
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
152-
if invalid {
153-
debug!("malformed span in suggestion: {:?}", subst);
154-
}
155-
invalid
156-
})
157-
}
158-
159147
/// Returns the assembled code suggestions, whether they should be shown with an underline
160148
/// and whether the substitution only differs in capitalization.
161149
pub fn splice_lines(&self, cm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
@@ -187,6 +175,15 @@ impl CodeSuggestion {
187175

188176
self.substitutions
189177
.iter()
178+
.filter(|subst| {
179+
// Suggestions coming from macros can have malformed spans. This is a heavy
180+
// handed approach to avoid ICEs by ignoring the suggestion outright.
181+
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
182+
if invalid {
183+
debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
184+
}
185+
!invalid
186+
})
190187
.cloned()
191188
.map(|mut substitution| {
192189
// Assumption: all spans are in the same file, and all spans

0 commit comments

Comments
 (0)