Skip to content

Commit 4809be0

Browse files
anyskaCentril
authored andcommitted
rustc_errors: Use ensure_source_file_source_present where necessary.
1 parent cf2d423 commit 4809be0

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

src/librustc_errors/emitter.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,11 @@ pub trait Emitter {
422422
span: &mut MultiSpan,
423423
children: &mut Vec<SubDiagnostic>,
424424
) {
425-
for span in iter::once(span).chain(children.iter_mut().map(|child| &mut child.span)) {
425+
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
426+
for span in iter::once(&mut *span).chain(children.iter_mut().map(|child| &mut child.span)) {
426427
self.fix_multispan_in_extern_macros(source_map, span);
427428
}
429+
debug!("fix_multispans_in_extern_macros: after: span={:?} children={:?}", span, children);
428430
}
429431

430432
// This "fixes" MultiSpans that contain `Span`s pointing to locations inside of external macros.
@@ -472,6 +474,7 @@ impl Emitter for EmitterWriter {
472474
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
473475
let mut children = diag.children.clone();
474476
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
477+
debug!("emit_diagnostic: suggestions={:?}", suggestions);
475478

476479
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
477480
&self.sm,
@@ -1533,6 +1536,7 @@ impl EmitterWriter {
15331536

15341537
// Render the replacements for each suggestion
15351538
let suggestions = suggestion.splice_lines(&**sm);
1539+
debug!("emit_suggestion_default: suggestions={:?}", suggestions);
15361540

15371541
if suggestions.is_empty() {
15381542
// Suggestions coming from macros can have malformed spans. This is a heavy handed

src/librustc_errors/json.rs

+5
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ impl DiagnosticSpanLine {
394394
je.sm
395395
.span_to_lines(span)
396396
.map(|lines| {
397+
// We can't get any lines if the source is unavailable.
398+
if !je.sm.ensure_source_file_source_present(lines.file.clone()) {
399+
return vec![];
400+
}
401+
397402
let sf = &*lines.file;
398403
lines
399404
.lines

src/librustc_errors/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ impl CodeSuggestion {
196196
let lines = sm.span_to_lines(bounding_span).ok()?;
197197
assert!(!lines.lines.is_empty());
198198

199+
// We can't splice anything if the source is unavailable.
200+
if !sm.ensure_source_file_source_present(lines.file.clone()) {
201+
return None;
202+
}
203+
199204
// To build up the result, we do this for each span:
200205
// - push the line segment trailing the previous span
201206
// (at the beginning a "phantom" span pointing at the start of the line)

src/test/ui/consts/miri_unleashed/mutable_const2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: internal compiler error: mutable allocation in constant
1010
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:355:17
13+
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:360:17
1414
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1515

1616
error: internal compiler error: unexpected panic

src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | produces_async! {}
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88
help: you can escape reserved keywords to use them as identifiers
99
|
10-
LL | r#async
11-
|
10+
LL | () => (pub fn r#async() {})
11+
| ^^^^^^^
1212

1313
error: aborting due to previous error
1414

src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | produces_async! {}
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88
help: you can escape reserved keywords to use them as identifiers
99
|
10-
LL | r#async
11-
|
10+
LL | () => (pub fn r#async() {})
11+
| ^^^^^^^
1212

1313
error: aborting due to previous error
1414

0 commit comments

Comments
 (0)