diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-01-16 18:27:18 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-01-16 18:55:23 -0800 |
| commit | 03240e1359f68bdddcdb236f3a89f9907b907449 (patch) | |
| tree | 9294d99b4c3e21da86d177f1e56e18ce837247c8 /src/librustc_errors | |
| parent | 10a9ea4c2622544d52ecef47fea0404a7ce0ace4 (diff) | |
| download | rust-03240e1359f68bdddcdb236f3a89f9907b907449.tar.gz rust-03240e1359f68bdddcdb236f3a89f9907b907449.zip | |
review comments
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 9 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 21 |
2 files changed, 14 insertions, 16 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index e37496f7299..b0e0cb611af 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1475,7 +1475,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(()); @@ -1497,9 +1501,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) { diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 889c84d6da1..827e9b831f3 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -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)> { @@ -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 |
