Start emitting labels even if their pointed to file is not available locally

This commit is contained in:
Oli Scherer 2022-11-15 15:24:54 +00:00
parent 19d7dceed3
commit 10b75cbbb0
4 changed files with 93 additions and 0 deletions

View file

@ -773,6 +773,7 @@ impl EmitterWriter {
draw_col_separator_no_space(buffer, line_offset, width_offset - 2);
}
#[instrument(level = "trace", skip(self), ret)]
fn render_source_line(
&self,
buffer: &mut StyledBuffer,
@ -804,6 +805,7 @@ impl EmitterWriter {
Some(s) => normalize_whitespace(&s),
None => return Vec::new(),
};
trace!(?source_string);
let line_offset = buffer.num_lines();
@ -1323,6 +1325,7 @@ impl EmitterWriter {
}
}
#[instrument(level = "trace", skip(self, args), ret)]
fn emit_message_default(
&mut self,
msp: &MultiSpan,
@ -1384,6 +1387,7 @@ impl EmitterWriter {
}
}
let mut annotated_files = FileWithAnnotatedLines::collect_annotations(self, args, msp);
trace!("{annotated_files:#?}");
// Make sure our primary file comes first
let primary_span = msp.primary_span().unwrap_or_default();
@ -1402,6 +1406,42 @@ impl EmitterWriter {
for annotated_file in annotated_files {
// we can't annotate anything if the source is unavailable.
if !sm.ensure_source_file_source_present(annotated_file.file.clone()) {
if !self.short_message {
// We'll just print an unannotated message.
for line in annotated_file.lines {
let mut annotations = line.annotations.clone();
annotations.sort_by_key(|a| Reverse(a.start_col));
let mut line_idx = buffer.num_lines();
buffer.append(
line_idx,
&format!(
"{}:{}:{}",
sm.filename_for_diagnostics(&annotated_file.file.name),
sm.doctest_offset_line(&annotated_file.file.name, line.line_index),
annotations[0].start_col + 1,
),
Style::LineAndColumn,
);
let prefix = if annotations.len() > 1 {
buffer.prepend(line_idx, "--> ", Style::LineNumber);
line_idx += 1;
"note: "
} else {
": "
};
for (i, annotation) in annotations.into_iter().enumerate() {
if let Some(label) = &annotation.label {
let style = if annotation.is_primary {
Style::LabelPrimary
} else {
Style::LabelSecondary
};
buffer.append(line_idx + i, prefix, style);
buffer.append(line_idx + i, label, style);
}
}
}
}
continue;
}
@ -1648,6 +1688,7 @@ impl EmitterWriter {
multilines.extend(&to_add);
}
}
trace!("buffer: {:#?}", buffer.render());
}
if let Some(tracked) = emitted_at {
@ -1971,6 +2012,7 @@ impl EmitterWriter {
Ok(())
}
#[instrument(level = "trace", skip(self, args, code, children, suggestions))]
fn emit_messages_default(
&mut self,
level: &Level,

View file

@ -0,0 +1,26 @@
// compile-flags: -Z simulate-remapped-rust-src-base=/rustc/xyz -Z translate-remapped-path-to-local-path=no
#![feature(const_swap)]
#![feature(const_mut_refs)]
use std::{
mem::{self, MaybeUninit},
ptr,
};
const X: () = {
let mut ptr1 = &1;
let mut ptr2 = &2;
// Swap them, bytewise.
unsafe {
ptr::swap_nonoverlapping(
&mut ptr1 as *mut _ as *mut MaybeUninit<u8>,
&mut ptr2 as *mut _ as *mut MaybeUninit<u8>,
mem::size_of::<&i32>(),
);
}
};
fn main() {
X
}

View file

@ -0,0 +1,23 @@
error[E0080]: evaluation of constant value failed
/rustc/xyz/library/core/src/ptr/mod.rs:929:14: inside `swap_nonoverlapping::<MaybeUninit<u8>>` at /rustc/xyz/library/core/src/ptr/mod.rs:929:14
/rustc/xyz/library/core/src/ptr/mod.rs:948:9: inside `ptr::swap_nonoverlapping_simple_untyped::<MaybeUninit<u8>>` at /rustc/xyz/library/core/src/ptr/mod.rs:948:9
--> /rustc/xyz/library/core/src/ptr/mod.rs:1139:9
note: unable to copy parts of a pointer from memory at alloc6+0x1
note: inside `std::ptr::read::<MaybeUninit<MaybeUninit<u8>>>` at /rustc/xyz/library/core/src/ptr/mod.rs:1139:9
/rustc/xyz/library/core/src/mem/mod.rs:776:17: inside `mem::swap_simple::<MaybeUninit<MaybeUninit<u8>>>` at /rustc/xyz/library/core/src/mem/mod.rs:776:17
|
::: $DIR/missing_span_in_backtrace.rs:16:9
|
LL | / ptr::swap_nonoverlapping(
LL | | &mut ptr1 as *mut _ as *mut MaybeUninit<u8>,
LL | | &mut ptr2 as *mut _ as *mut MaybeUninit<u8>,
LL | | mem::size_of::<&i32>(),
LL | | );
| |_________- inside `X` at $DIR/missing_span_in_backtrace.rs:16:9
|
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.

View file

@ -7,6 +7,7 @@ error[E0277]: `MyError` doesn't implement `std::fmt::Display`
= help: the trait `std::fmt::Display` is not implemented for `MyError`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `std::error::Error`
/rustc/xyz/library/core/src/error.rs:31:26: required by this bound in `std::error::Error`
error[E0277]: `MyError` doesn't implement `Debug`
--> $DIR/issue-71363.rs:4:6
@ -17,6 +18,7 @@ error[E0277]: `MyError` doesn't implement `Debug`
= help: the trait `Debug` is not implemented for `MyError`
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
note: required by a bound in `std::error::Error`
/rustc/xyz/library/core/src/error.rs:31:18: required by this bound in `std::error::Error`
help: consider annotating `MyError` with `#[derive(Debug)]`
|
3 | #[derive(Debug)]