about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/json.rs
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-07-04 16:22:35 +0200
committerGitHub <noreply@github.com>2025-07-04 16:22:35 +0200
commit324aa5d4baebcd925a18f2dc784f8a0d90c6ec77 (patch)
tree3b357dc03d3a7e5e44c289179bc62df7e9fb817c /compiler/rustc_errors/src/json.rs
parentda25619e2ab51fe3930e6a2a14aafb19f6c860ec (diff)
parent6bef238b6346911d29a1ee0b067dc003da15f828 (diff)
downloadrust-324aa5d4baebcd925a18f2dc784f8a0d90c6ec77.tar.gz
rust-324aa5d4baebcd925a18f2dc784f8a0d90c6ec77.zip
Rollup merge of #143286 - Muscraft:track-diagnostics-note, r=WaffleLapkin
Make -Ztrack-diagnostics emit like a note

[#t-compiler/diagnostics > Rendering -Ztrack-diagnostics like a note](https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/Rendering.20-Ztrack-diagnostics.20like.20a.20note/with/526608647)

As discussed on the Zulip thread above, I want to make `-Ztrack-diagnostics` emit like a `note`. This is because I find its current output jarring, and the fact that it gets rendered completely left-aligned, [even in the middle of a snippet](https://github.com/rust-lang/rust/blob/86e05cd300fac9e83e812c4d46582b48db780d8f/tests/ui/track-diagnostics/track6.stderr), seems like something that should be changed. Turning it into a `note` seems like the best choice, as it would align it with the rest of the output, and `note` is already used for somewhat similar things, like seeing why a lint was fired.

---

Note: turning `-Ztrack-diagnostics` into a `note` will also make `annotate-snippets` API a bit cleaner
Diffstat (limited to 'compiler/rustc_errors/src/json.rs')
-rw-r--r--compiler/rustc_errors/src/json.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs
index 4348610be0a..719d4ca625a 100644
--- a/compiler/rustc_errors/src/json.rs
+++ b/compiler/rustc_errors/src/json.rs
@@ -372,13 +372,16 @@ impl Diagnostic {
         };
         let level = diag.level.to_str();
         let spans = DiagnosticSpan::from_multispan(&diag.span, &args, je);
-        let children = diag
+        let mut children: Vec<Diagnostic> = diag
             .children
             .iter()
             .map(|c| Diagnostic::from_sub_diagnostic(c, &args, je))
             .chain(sugg)
             .collect();
-
+        if je.track_diagnostics && diag.span.has_primary_spans() && !diag.span.is_dummy() {
+            children
+                .insert(0, Diagnostic::from_sub_diagnostic(&diag.emitted_at_sub_diag(), &args, je));
+        }
         let buf = BufWriter::default();
         let mut dst: Destination = Box::new(buf.clone());
         let short = je.json_rendered.short();