diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 7e1effd8378..4df2198fb0e 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1408,7 +1408,7 @@ impl EmitterWriter { 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 { + for (annotation_id, line) in annotated_file.lines.into_iter().enumerate() { let mut annotations = line.annotations.clone(); annotations.sort_by_key(|a| Reverse(a.start_col)); let mut line_idx = buffer.num_lines(); @@ -1422,12 +1422,12 @@ impl EmitterWriter { ), Style::LineAndColumn, ); - let prefix = if annotations.len() > 1 { + if annotation_id == 0 { buffer.prepend(line_idx, "--> ", Style::LineNumber); + for _ in 0..max_line_num_len { + buffer.prepend(line_idx, " ", Style::NoStyle); + } line_idx += 1; - "note: " - } else { - ": " }; for (i, annotation) in annotations.into_iter().enumerate() { if let Some(label) = &annotation.label { @@ -1436,7 +1436,19 @@ impl EmitterWriter { } else { Style::LabelSecondary }; - buffer.append(line_idx + i, prefix, style); + if annotation_id == 0 { + buffer.prepend(line_idx, " |", Style::LineNumber); + for _ in 0..max_line_num_len { + buffer.prepend(line_idx, " ", Style::NoStyle); + } + line_idx += 1; + buffer.append(line_idx + i, " = note: ", style); + for _ in 0..max_line_num_len { + buffer.prepend(line_idx, " ", Style::NoStyle); + } + } else { + buffer.append(line_idx + i, ": ", style); + } buffer.append(line_idx + i, label, style); } } diff --git a/src/test/ui/consts/missing_span_in_backtrace.stderr b/src/test/ui/consts/missing_span_in_backtrace.stderr index f2a79a1d3d3..b8c20df8700 100644 --- a/src/test/ui/consts/missing_span_in_backtrace.stderr +++ b/src/test/ui/consts/missing_span_in_backtrace.stderr @@ -1,16 +1,18 @@ error[E0080]: evaluation of constant value failed -/rustc/xyz/library/core/src/ptr/mod.rs:1135:9: unable to copy parts of a pointer from memory at alloc10 + --> /rustc/xyz/library/core/src/ptr/mod.rs:1135:9 + | + = note: unable to copy parts of a pointer from memory at alloc10 | = 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 note: inside `std::ptr::read::>>` -/rustc/xyz/library/core/src/ptr/mod.rs:1135:9 + --> /rustc/xyz/library/core/src/ptr/mod.rs:1135:9 note: inside `mem::swap_simple::>>` -/rustc/xyz/library/core/src/mem/mod.rs:773:17 + --> /rustc/xyz/library/core/src/mem/mod.rs:773:17 note: inside `ptr::swap_nonoverlapping_simple_untyped::>` -/rustc/xyz/library/core/src/ptr/mod.rs:944:9 + --> /rustc/xyz/library/core/src/ptr/mod.rs:944:9 note: inside `swap_nonoverlapping::>` -/rustc/xyz/library/core/src/ptr/mod.rs:925:14 + --> /rustc/xyz/library/core/src/ptr/mod.rs:925:14 note: inside `X` --> $DIR/missing_span_in_backtrace.rs:16:9 | diff --git a/src/test/ui/span/issue-71363.stderr b/src/test/ui/span/issue-71363.stderr index c0268ec683f..789a386bf66 100644 --- a/src/test/ui/span/issue-71363.stderr +++ b/src/test/ui/span/issue-71363.stderr @@ -7,7 +7,9 @@ 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` + --> /rustc/xyz/library/core/src/error.rs:31:26 + | + = note: required by this bound in `std::error::Error` error[E0277]: `MyError` doesn't implement `Debug` --> $DIR/issue-71363.rs:4:6 @@ -18,7 +20,9 @@ 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` + --> /rustc/xyz/library/core/src/error.rs:31:18 + | + = note: required by this bound in `std::error::Error` help: consider annotating `MyError` with `#[derive(Debug)]` | 3 | #[derive(Debug)]