1
Fork 0

review comments

This commit is contained in:
Esteban Küber 2020-01-16 18:27:18 -08:00
parent 10a9ea4c26
commit 03240e1359
3 changed files with 15 additions and 17 deletions

View file

@ -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