Skip to content

Commit 504a55d

Browse files
committed
refactor: Move drawing seconday messages to a function
1 parent 4e97337 commit 504a55d

File tree

1 file changed

+47
-27
lines changed

1 file changed

+47
-27
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,33 +1475,15 @@ impl HumanEmitter {
14751475

14761476
if !msp.has_primary_spans() && !msp.has_span_labels() && is_secondary && !self.short_message
14771477
{
1478-
// This is a secondary message with no span info
1479-
for _ in 0..max_line_num_len {
1480-
buffer.prepend(0, " ", Style::NoStyle);
1481-
}
1482-
self.draw_note_separator(&mut buffer, 0, max_line_num_len + 1, is_cont);
1483-
if *level != Level::FailureNote {
1484-
buffer.append(0, level.to_str(), Style::MainHeaderMsg);
1485-
buffer.append(0, ": ", Style::NoStyle);
1486-
}
1487-
let printed_lines =
1488-
self.msgs_to_buffer(&mut buffer, msgs, args, max_line_num_len, "note", None);
1489-
if is_cont && matches!(self.theme, OutputTheme::Unicode) {
1490-
// There's another note after this one, associated to the subwindow above.
1491-
// We write additional vertical lines to join them:
1492-
// ╭▸ test.rs:3:3
1493-
// │
1494-
// 3 │ code
1495-
// │ ━━━━
1496-
// │
1497-
// ├ note: foo
1498-
// │ bar
1499-
// ╰ note: foo
1500-
// bar
1501-
for i in 1..=printed_lines {
1502-
self.draw_col_separator_no_space(&mut buffer, i, max_line_num_len + 1);
1503-
}
1504-
}
1478+
self.draw_secondary_message(
1479+
&mut buffer,
1480+
msgs,
1481+
args,
1482+
0,
1483+
level,
1484+
max_line_num_len,
1485+
is_cont,
1486+
);
15051487
} else {
15061488
let mut label_width = 0;
15071489
// The failure note level itself does not provide any useful diagnostic information
@@ -2740,6 +2722,44 @@ impl HumanEmitter {
27402722
*row_num += 1;
27412723
}
27422724

2725+
fn draw_secondary_message(
2726+
&self,
2727+
buffer: &mut StyledBuffer,
2728+
msgs: &[(DiagMessage, Style)],
2729+
args: &FluentArgs<'_>,
2730+
line: usize,
2731+
level: &Level,
2732+
max_line_num_len: usize,
2733+
is_cont: bool,
2734+
) {
2735+
// This is a secondary message with no sphan info
2736+
for _ in 0..max_line_num_len {
2737+
buffer.prepend(line, " ", Style::NoStyle);
2738+
}
2739+
self.draw_note_separator(buffer, line, max_line_num_len + 1, is_cont);
2740+
if *level != Level::FailureNote {
2741+
buffer.append(line, level.to_str(), Style::MainHeaderMsg);
2742+
buffer.append(line, ": ", Style::NoStyle);
2743+
}
2744+
let printed_lines = self.msgs_to_buffer(buffer, msgs, args, max_line_num_len, "note", None);
2745+
if is_cont && matches!(self.theme, OutputTheme::Unicode) {
2746+
// There's another note after this one, associated to the subwindow above.
2747+
// We write additional vertical lines to join them:
2748+
// ╭▸ test.rs:3:3
2749+
// │
2750+
// 3 │ code
2751+
// │ ━━━━
2752+
// │
2753+
// ├ note: foo
2754+
// │ bar
2755+
// ╰ note: foo
2756+
// bar
2757+
for i in 1 + line..=printed_lines + line {
2758+
self.draw_col_separator_no_space(buffer, i, max_line_num_len + 1);
2759+
}
2760+
}
2761+
}
2762+
27432763
fn underline(&self, is_primary: bool) -> UnderlineParts {
27442764
// X0 Y0
27452765
// label_start > ┯━━━━ < underline

0 commit comments

Comments
 (0)