Skip to content

Commit a6b31eb

Browse files
committed
Align multiline messages to their label (add left margin)
1 parent abf70a9 commit a6b31eb

File tree

13 files changed

+1310
-1298
lines changed

13 files changed

+1310
-1298
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,22 +1266,37 @@ impl EmitterWriter {
12661266
}
12671267
self.msg_to_buffer(&mut buffer, msg, max_line_num_len, "note", None);
12681268
} else {
1269+
let mut label_width = 0;
12691270
// The failure note level itself does not provide any useful diagnostic information
12701271
if *level != Level::FailureNote {
12711272
buffer.append(0, level.to_str(), Style::Level(*level));
1273+
label_width += level.to_str().len();
12721274
}
12731275
// only render error codes, not lint codes
12741276
if let Some(DiagnosticId::Error(ref code)) = *code {
12751277
buffer.append(0, "[", Style::Level(*level));
12761278
buffer.append(0, &code, Style::Level(*level));
12771279
buffer.append(0, "]", Style::Level(*level));
1280+
label_width += 2 + code.len();
12781281
}
12791282
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
12801283
if *level != Level::FailureNote {
12811284
buffer.append(0, ": ", header_style);
1285+
label_width += 2;
12821286
}
12831287
for &(ref text, _) in msg.iter() {
1284-
buffer.append(0, &replace_tabs(text), header_style);
1288+
// Account for newlines to align output to its label.
1289+
for (line, text) in replace_tabs(text).lines().enumerate() {
1290+
buffer.append(
1291+
0 + line,
1292+
&format!(
1293+
"{}{}",
1294+
if line == 0 { String::new() } else { " ".repeat(label_width) },
1295+
text
1296+
),
1297+
header_style,
1298+
);
1299+
}
12851300
}
12861301
}
12871302

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ fn compare_predicate_entailment<'tcx>(
232232
span,
233233
impl_m_hir_id,
234234
ObligationCauseCode::CompareImplMethodObligation {
235-
item_name: impl_m.ident.name,
236235
impl_item_def_id: impl_m.def_id,
237236
trait_item_def_id: trait_m.def_id,
238237
},

src/test/ui/attributes/key-value-expansion.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ LL | bug!();
1616
= note: this error originates in the macro `bug` (in Nightly builds, run with -Z macro-backtrace for more info)
1717

1818
error: unexpected token: `{
19-
let res =
20-
::alloc::fmt::format(::core::fmt::Arguments::new_v1(&[""],
21-
&match (&"u8",) {
22-
_args =>
23-
[::core::fmt::ArgumentV1::new(_args.0,
24-
::core::fmt::Display::fmt)],
25-
}));
26-
res
27-
}.as_str()`
19+
let res =
20+
::alloc::fmt::format(::core::fmt::Arguments::new_v1(&[""],
21+
&match (&"u8",) {
22+
_args =>
23+
[::core::fmt::ArgumentV1::new(_args.0,
24+
::core::fmt::Display::fmt)],
25+
}));
26+
res
27+
}.as_str()`
2828
--> $DIR/key-value-expansion.rs:48:23
2929
|
3030
LL | doc_comment! {format!("{coor}", coor = stringify!($t1)).as_str()}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
error: <unknown>:0:0: in function test i32 (i32, i32, i32, i32, i32): call to non-secure function would require passing arguments on stack
22

3-
43
error: aborting due to previous error
54

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
error: <unknown>:0:0: in function entry_function i32 (i32, i32, i32, i32, i32): secure entry function requires arguments on stack
22

3-
43
error: aborting due to previous error
54

0 commit comments

Comments
 (0)