Skip to content

Commit f89d623

Browse files
committed
Properly indent messages
1 parent 99348a5 commit f89d623

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ impl EmitterWriter {
14081408
if !sm.ensure_source_file_source_present(annotated_file.file.clone()) {
14091409
if !self.short_message {
14101410
// We'll just print an unannotated message.
1411-
for line in annotated_file.lines {
1411+
for (annotation_id, line) in annotated_file.lines.into_iter().enumerate() {
14121412
let mut annotations = line.annotations.clone();
14131413
annotations.sort_by_key(|a| Reverse(a.start_col));
14141414
let mut line_idx = buffer.num_lines();
@@ -1422,12 +1422,12 @@ impl EmitterWriter {
14221422
),
14231423
Style::LineAndColumn,
14241424
);
1425-
let prefix = if annotations.len() > 1 {
1425+
if annotation_id == 0 {
14261426
buffer.prepend(line_idx, "--> ", Style::LineNumber);
1427+
for _ in 0..max_line_num_len {
1428+
buffer.prepend(line_idx, " ", Style::NoStyle);
1429+
}
14271430
line_idx += 1;
1428-
"note: "
1429-
} else {
1430-
": "
14311431
};
14321432
for (i, annotation) in annotations.into_iter().enumerate() {
14331433
if let Some(label) = &annotation.label {
@@ -1436,7 +1436,19 @@ impl EmitterWriter {
14361436
} else {
14371437
Style::LabelSecondary
14381438
};
1439-
buffer.append(line_idx + i, prefix, style);
1439+
if annotation_id == 0 {
1440+
buffer.prepend(line_idx, " |", Style::LineNumber);
1441+
for _ in 0..max_line_num_len {
1442+
buffer.prepend(line_idx, " ", Style::NoStyle);
1443+
}
1444+
line_idx += 1;
1445+
buffer.append(line_idx + i, " = note: ", style);
1446+
for _ in 0..max_line_num_len {
1447+
buffer.prepend(line_idx, " ", Style::NoStyle);
1448+
}
1449+
} else {
1450+
buffer.append(line_idx + i, ": ", style);
1451+
}
14401452
buffer.append(line_idx + i, label, style);
14411453
}
14421454
}

src/test/ui/consts/missing_span_in_backtrace.stderr

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
error[E0080]: evaluation of constant value failed
2-
/rustc/xyz/library/core/src/ptr/mod.rs:1135:9: unable to copy parts of a pointer from memory at alloc10
2+
--> /rustc/xyz/library/core/src/ptr/mod.rs:1135:9
3+
|
4+
= note: unable to copy parts of a pointer from memory at alloc10
35
|
46
= help: this code performed an operation that depends on the underlying bytes representing a pointer
57
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
68
note: inside `std::ptr::read::<MaybeUninit<MaybeUninit<u8>>>`
7-
/rustc/xyz/library/core/src/ptr/mod.rs:1135:9
9+
--> /rustc/xyz/library/core/src/ptr/mod.rs:1135:9
810
note: inside `mem::swap_simple::<MaybeUninit<MaybeUninit<u8>>>`
9-
/rustc/xyz/library/core/src/mem/mod.rs:773:17
11+
--> /rustc/xyz/library/core/src/mem/mod.rs:773:17
1012
note: inside `ptr::swap_nonoverlapping_simple_untyped::<MaybeUninit<u8>>`
11-
/rustc/xyz/library/core/src/ptr/mod.rs:944:9
13+
--> /rustc/xyz/library/core/src/ptr/mod.rs:944:9
1214
note: inside `swap_nonoverlapping::<MaybeUninit<u8>>`
13-
/rustc/xyz/library/core/src/ptr/mod.rs:925:14
15+
--> /rustc/xyz/library/core/src/ptr/mod.rs:925:14
1416
note: inside `X`
1517
--> $DIR/missing_span_in_backtrace.rs:16:9
1618
|

src/test/ui/span/issue-71363.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ error[E0277]: `MyError` doesn't implement `std::fmt::Display`
77
= help: the trait `std::fmt::Display` is not implemented for `MyError`
88
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
99
note: required by a bound in `std::error::Error`
10-
/rustc/xyz/library/core/src/error.rs:31:26: required by this bound in `std::error::Error`
10+
--> /rustc/xyz/library/core/src/error.rs:31:26
11+
|
12+
= note: required by this bound in `std::error::Error`
1113

1214
error[E0277]: `MyError` doesn't implement `Debug`
1315
--> $DIR/issue-71363.rs:4:6
@@ -18,7 +20,9 @@ error[E0277]: `MyError` doesn't implement `Debug`
1820
= help: the trait `Debug` is not implemented for `MyError`
1921
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
2022
note: required by a bound in `std::error::Error`
21-
/rustc/xyz/library/core/src/error.rs:31:18: required by this bound in `std::error::Error`
23+
--> /rustc/xyz/library/core/src/error.rs:31:18
24+
|
25+
= note: required by this bound in `std::error::Error`
2226
help: consider annotating `MyError` with `#[derive(Debug)]`
2327
|
2428
3 | #[derive(Debug)]

0 commit comments

Comments
 (0)