diff options
| author | Ana-Maria Mihalache <mihalacheana.maria@yahoo.com> | 2020-03-05 15:31:11 +0000 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-10 07:26:27 +0100 |
| commit | 4809be0137d86a1a6a74848640ab5c08eeba8515 (patch) | |
| tree | 098bf6eeeb0452decfb46ad2f24cbcb7e702ac65 /src/librustc_errors | |
| parent | cf2d4236eb311b80407678b0527b810ecdd335b7 (diff) | |
| download | rust-4809be0137d86a1a6a74848640ab5c08eeba8515.tar.gz rust-4809be0137d86a1a6a74848640ab5c08eeba8515.zip | |
rustc_errors: Use ensure_source_file_source_present where necessary.
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 6 | ||||
| -rw-r--r-- | src/librustc_errors/json.rs | 5 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 5 |
3 files changed, 15 insertions, 1 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index b38ea6b4241..03f83e61636 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -422,9 +422,11 @@ pub trait Emitter { span: &mut MultiSpan, children: &mut Vec<SubDiagnostic>, ) { - for span in iter::once(span).chain(children.iter_mut().map(|child| &mut child.span)) { + debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children); + for span in iter::once(&mut *span).chain(children.iter_mut().map(|child| &mut child.span)) { self.fix_multispan_in_extern_macros(source_map, span); } + debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children); } // This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros. @@ -472,6 +474,7 @@ impl Emitter for EmitterWriter { fn emit_diagnostic(&mut self, diag: &Diagnostic) { let mut children = diag.children.clone(); let (mut primary_span, suggestions) = self.primary_span_formatted(&diag); + debug!("emit_diagnostic: suggestions={:?}", suggestions); self.fix_multispans_in_extern_macros_and_render_macro_backtrace( &self.sm, @@ -1533,6 +1536,7 @@ impl EmitterWriter { // Render the replacements for each suggestion let suggestions = suggestion.splice_lines(&**sm); + debug!("emit_suggestion_default: suggestions={:?}", suggestions); if suggestions.is_empty() { // Suggestions coming from macros can have malformed spans. This is a heavy handed diff --git a/src/librustc_errors/json.rs b/src/librustc_errors/json.rs index 0767b8dda9b..1382825922b 100644 --- a/src/librustc_errors/json.rs +++ b/src/librustc_errors/json.rs @@ -394,6 +394,11 @@ impl DiagnosticSpanLine { je.sm .span_to_lines(span) .map(|lines| { + // We can't get any lines if the source is unavailable. + if !je.sm.ensure_source_file_source_present(lines.file.clone()) { + return vec![]; + } + let sf = &*lines.file; lines .lines diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index f0e388a597b..bed26c3736b 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -196,6 +196,11 @@ impl CodeSuggestion { let lines = sm.span_to_lines(bounding_span).ok()?; assert!(!lines.lines.is_empty()); + // We can't splice anything if the source is unavailable. + if !sm.ensure_source_file_source_present(lines.file.clone()) { + return None; + } + // To build up the result, we do this for each span: // - push the line segment trailing the previous span // (at the beginning a "phantom" span pointing at the start of the line) |
