mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
rustc_errors: Use ensure_source_file_source_present where necessary.
This commit is contained in:
parent
cf2d4236eb
commit
4809be0137
@ -422,9 +422,11 @@ pub trait Emitter {
|
|||||||
span: &mut MultiSpan,
|
span: &mut MultiSpan,
|
||||||
children: &mut Vec<SubDiagnostic>,
|
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);
|
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.
|
// 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) {
|
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
|
||||||
let mut children = diag.children.clone();
|
let mut children = diag.children.clone();
|
||||||
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
|
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.fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||||
&self.sm,
|
&self.sm,
|
||||||
@ -1533,6 +1536,7 @@ impl EmitterWriter {
|
|||||||
|
|
||||||
// Render the replacements for each suggestion
|
// Render the replacements for each suggestion
|
||||||
let suggestions = suggestion.splice_lines(&**sm);
|
let suggestions = suggestion.splice_lines(&**sm);
|
||||||
|
debug!("emit_suggestion_default: suggestions={:?}", suggestions);
|
||||||
|
|
||||||
if suggestions.is_empty() {
|
if suggestions.is_empty() {
|
||||||
// Suggestions coming from macros can have malformed spans. This is a heavy handed
|
// Suggestions coming from macros can have malformed spans. This is a heavy handed
|
||||||
|
@ -394,6 +394,11 @@ impl DiagnosticSpanLine {
|
|||||||
je.sm
|
je.sm
|
||||||
.span_to_lines(span)
|
.span_to_lines(span)
|
||||||
.map(|lines| {
|
.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;
|
let sf = &*lines.file;
|
||||||
lines
|
lines
|
||||||
.lines
|
.lines
|
||||||
|
@ -196,6 +196,11 @@ impl CodeSuggestion {
|
|||||||
let lines = sm.span_to_lines(bounding_span).ok()?;
|
let lines = sm.span_to_lines(bounding_span).ok()?;
|
||||||
assert!(!lines.lines.is_empty());
|
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:
|
// To build up the result, we do this for each span:
|
||||||
// - push the line segment trailing the previous span
|
// - push the line segment trailing the previous span
|
||||||
// (at the beginning a "phantom" span pointing at the start of the line)
|
// (at the beginning a "phantom" span pointing at the start of the line)
|
||||||
|
@ -10,7 +10,7 @@ error: internal compiler error: mutable allocation in constant
|
|||||||
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:355:17
|
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:360:17
|
||||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||||
|
|
||||||
error: internal compiler error: unexpected panic
|
error: internal compiler error: unexpected panic
|
||||||
|
@ -7,8 +7,8 @@ LL | produces_async! {}
|
|||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
help: you can escape reserved keywords to use them as identifiers
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
|
||||||
LL | r#async
|
LL | () => (pub fn r#async() {})
|
||||||
|
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ LL | produces_async! {}
|
|||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
help: you can escape reserved keywords to use them as identifiers
|
help: you can escape reserved keywords to use them as identifiers
|
||||||
|
|
|
|
||||||
LL | r#async
|
LL | () => (pub fn r#async() {})
|
||||||
|
|
| ^^^^^^^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user