diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-01-24 18:03:09 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-01-24 18:03:09 -0800 |
| commit | b626202087dff72216c14e08e11d936136dc2126 (patch) | |
| tree | 87ee0f5c50d07ee72ced10adf58c5652c79f0857 /src/librustc_errors | |
| parent | c2d141df59703393c0c683abc259f9a8c3be041a (diff) | |
| download | rust-b626202087dff72216c14e08e11d936136dc2126.tar.gz rust-b626202087dff72216c14e08e11d936136dc2126.zip | |
Do not ICE on multipart suggestions touching multiple files
When encountering a multipart suggestion with spans belonging to different contexts, skip that suggestion.
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/lib.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 827e9b831f3..17b293401f8 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -185,16 +185,17 @@ impl CodeSuggestion { !invalid }) .cloned() - .map(|mut substitution| { + .filter_map(|mut substitution| { // Assumption: all spans are in the same file, and all spans // are disjoint. Sort in ascending order. substitution.parts.sort_by_key(|part| part.span.lo()); // Find the bounding span. - let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap(); - let hi = substitution.parts.iter().map(|part| part.span.hi()).max().unwrap(); + let lo = substitution.parts.iter().map(|part| part.span.lo()).min()?; + let hi = substitution.parts.iter().map(|part| part.span.hi()).max()?; let bounding_span = Span::with_root_ctxt(lo, hi); - let lines = cm.span_to_lines(bounding_span).unwrap(); + // The different spans might belong to different contexts, if so ignore suggestion. + let lines = cm.span_to_lines(bounding_span).ok()?; assert!(!lines.lines.is_empty()); // To build up the result, we do this for each span: @@ -244,7 +245,7 @@ impl CodeSuggestion { while buf.ends_with('\n') { buf.pop(); } - (buf, substitution.parts, only_capitalization) + Some((buf, substitution.parts, only_capitalization)) }) .collect() } |
