Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank authored and Mark-Simulacrum committed Jan 23, 2020
1 parent 356ff77 commit b0a99fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,11 @@ impl EmitterWriter {
Some(ref sm) => sm,
None => return Ok(()),
};
if !suggestion.has_valid_spans(&**sm) {

// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(&**sm);

if suggestions.is_empty() {
// Suggestions coming from macros can have malformed spans. This is a heavy handed
// approach to avoid ICEs by ignoring the suggestion outright.
return Ok(());
Expand All @@ -1499,9 +1503,6 @@ impl EmitterWriter {
Some(Style::HeaderMsg),
);

// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(&**sm);

let mut row_num = 2;
let mut notice_capitalization = false;
for (complete, parts, only_capitalization) in suggestions.iter().take(MAX_SUGGESTIONS) {
Expand Down
21 changes: 9 additions & 12 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,6 @@ pub struct SubstitutionPart {
}

impl CodeSuggestion {
/// Suggestions coming from macros can have malformed spans. This is a heavy handed approach
/// to avoid ICEs by ignoring the suggestion outright.
pub fn has_valid_spans(&self, cm: &SourceMap) -> bool {
!self.substitutions.iter().any(|subst| {
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
if invalid {
debug!("malformed span in suggestion: {:?}", subst);
}
invalid
})
}

/// Returns the assembled code suggestions, whether they should be shown with an underline
/// and whether the substitution only differs in capitalization.
pub fn splice_lines(&self, cm: &SourceMap) -> Vec<(String, Vec<SubstitutionPart>, bool)> {
Expand Down Expand Up @@ -187,6 +175,15 @@ impl CodeSuggestion {

self.substitutions
.iter()
.filter(|subst| {
// Suggestions coming from macros can have malformed spans. This is a heavy
// handed approach to avoid ICEs by ignoring the suggestion outright.
let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err());
if invalid {
debug!("splice_lines: suggestion contains an invalid span: {:?}", subst);
}
!invalid
})
.cloned()
.map(|mut substitution| {
// Assumption: all spans are in the same file, and all spans
Expand Down

0 comments on commit b0a99fd

Please sign in to comment.