Skip to content

Commit 2233519

Browse files
committed
refactor: Emit -Ztrack-diagnostics in emit_messages_default
1 parent 504a55d commit 2233519

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,6 @@ impl HumanEmitter {
14681468
level: &Level,
14691469
max_line_num_len: usize,
14701470
is_secondary: bool,
1471-
emitted_at: Option<&DiagLocation>,
14721471
is_cont: bool,
14731472
) -> io::Result<()> {
14741473
let mut buffer = StyledBuffer::new();
@@ -1960,12 +1959,6 @@ impl HumanEmitter {
19601959
trace!("buffer: {:#?}", buffer.render());
19611960
}
19621961

1963-
if let Some(tracked) = emitted_at {
1964-
let track = format!("-Ztrack-diagnostics: created at {tracked}");
1965-
let len = buffer.num_lines();
1966-
buffer.append(len, &track, Style::NoStyle);
1967-
}
1968-
19691962
// final step: take our styled buffer, render it, then output it
19701963
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)?;
19711964

@@ -2477,34 +2470,46 @@ impl HumanEmitter {
24772470
level,
24782471
max_line_num_len,
24792472
false,
2480-
emitted_at,
24812473
!children.is_empty()
24822474
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden),
24832475
) {
24842476
Ok(()) => {
2477+
let mut buffer = StyledBuffer::new();
2478+
let primary_span = span.primary_span().unwrap_or_default();
2479+
if let (Some(tracked), false) = (emitted_at, primary_span.is_dummy()) {
2480+
if !self.short_message {
2481+
let track = format!("-Ztrack-diagnostics: created at {tracked}");
2482+
buffer.append(0, &track, Style::NoStyle);
2483+
}
2484+
}
24852485
if !children.is_empty()
24862486
|| suggestions.iter().any(|s| s.style != SuggestionStyle::CompletelyHidden)
24872487
{
2488-
let mut buffer = StyledBuffer::new();
2488+
let line_offest = buffer.num_lines();
24892489
if !self.short_message {
24902490
if let Some(child) = children.iter().next()
24912491
&& child.span.primary_spans().is_empty()
24922492
{
24932493
// We'll continue the vertical bar to point into the next note.
2494-
self.draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
2494+
self.draw_col_separator_no_space(
2495+
&mut buffer,
2496+
line_offest,
2497+
max_line_num_len + 1,
2498+
);
24952499
} else {
24962500
// We'll close the vertical bar to visually end the code window.
2497-
self.draw_col_separator_end(&mut buffer, 0, max_line_num_len + 1);
2501+
self.draw_col_separator_end(
2502+
&mut buffer,
2503+
line_offest,
2504+
max_line_num_len + 1,
2505+
);
24982506
}
24992507
}
2500-
if let Err(e) = emit_to_destination(
2501-
&buffer.render(),
2502-
level,
2503-
&mut self.dst,
2504-
self.short_message,
2505-
) {
2506-
panic!("failed to emit error: {e}")
2507-
}
2508+
}
2509+
if let Err(e) =
2510+
emit_to_destination(&buffer.render(), level, &mut self.dst, self.short_message)
2511+
{
2512+
panic!("failed to emit error: {e}")
25082513
}
25092514
if !self.short_message {
25102515
for (i, child) in children.iter().enumerate() {
@@ -2523,7 +2528,6 @@ impl HumanEmitter {
25232528
&child.level,
25242529
max_line_num_len,
25252530
true,
2526-
None,
25272531
!should_close,
25282532
) {
25292533
panic!("failed to emit error: {err}");
@@ -2543,7 +2547,6 @@ impl HumanEmitter {
25432547
&Level::Help,
25442548
max_line_num_len,
25452549
true,
2546-
None,
25472550
// FIXME: this needs to account for the suggestion type,
25482551
// some don't take any space.
25492552
i + 1 != suggestions.len(),

0 commit comments

Comments
 (0)