diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-11-15 15:24:54 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-12-06 18:59:46 +0000 |
| commit | 10b75cbbb04796cdf5264616493f3a20eb43ed0c (patch) | |
| tree | b012753c128f4159c32345efc1e4bebea62a5a66 | |
| parent | 19d7dceed302b254f21fd77084ff6b468305058a (diff) | |
| download | rust-10b75cbbb04796cdf5264616493f3a20eb43ed0c.tar.gz rust-10b75cbbb04796cdf5264616493f3a20eb43ed0c.zip | |
Start emitting labels even if their pointed to file is not available locally
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 42 | ||||
| -rw-r--r-- | src/test/ui/consts/missing_span_in_backtrace.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/consts/missing_span_in_backtrace.stderr | 23 | ||||
| -rw-r--r-- | src/test/ui/span/issue-71363.stderr | 2 |
4 files changed, 93 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index ce5a91ef4a2..7e1effd8378 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -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, diff --git a/src/test/ui/consts/missing_span_in_backtrace.rs b/src/test/ui/consts/missing_span_in_backtrace.rs new file mode 100644 index 00000000000..dd4ee3bed44 --- /dev/null +++ b/src/test/ui/consts/missing_span_in_backtrace.rs @@ -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 +} diff --git a/src/test/ui/consts/missing_span_in_backtrace.stderr b/src/test/ui/consts/missing_span_in_backtrace.stderr new file mode 100644 index 00000000000..9969d5b63e7 --- /dev/null +++ b/src/test/ui/consts/missing_span_in_backtrace.stderr @@ -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`. diff --git a/src/test/ui/span/issue-71363.stderr b/src/test/ui/span/issue-71363.stderr index 04e2b46c317..c0268ec683f 100644 --- a/src/test/ui/span/issue-71363.stderr +++ b/src/test/ui/span/issue-71363.stderr @@ -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)] |
