about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/json.rs
AgeCommit message (Collapse)AuthorLines
2025-07-03refactor: Make -Ztrack-diagnostics emit like a noteScott Schafer-2/+5
2025-06-23Rollup merge of #142784 - Kobzol:timings-codegen, r=nnethercoteJubilee-0/+1
Add codegen timing section And since we now start and end the sections also using separate functions, also add some light checking if we're generating the sections correctly. I'm integrating `--timings` into Cargo, and I realized that the codegen timings would be quite useful for that. Frontend can be computed simply as `[start of compilation, start of codegen]` for now. r? `@nnethercote`
2025-06-23Add codegen timing sectionJakub Beránek-0/+1
2025-06-19Extract Translator structCameron Steffen-26/+14
2025-06-16Add infrastructure for emitting timing sectionsJakub Beránek-1/+28
2025-04-03Split ExpectationLintId off LevelOli Scherer-1/+1
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-5/+5
2025-01-20don't ICE when emitting linker errors during `-Z link-only`jyn-17/+30
note that this still ICEs when passed `-Z link-only --error-format json` because i can't be bothered to fix it right now
2025-01-19Manual cleanup of some `is_{or_none|some_and}` usagesYotam Ofek-1/+2
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-1/+1
2024-12-06Store a single copy of the error registry in DiagCtxtbjorn3-9/+11
And pass this to the individual emitters when necessary.
2024-11-11Auto merge of #126597 - estebank:unicode-output, r=fmeasebors-1/+6
Add Unicode block-drawing compiler output support Add nightly-only theming support to rustc output using Unicode box drawing characters instead of ASCII-art to draw the terminal UI. In order to enable, the flags `-Zunstable-options=yes --error-format=human-unicode` must be passed in. After: ``` error: foo ╭▸ test.rs:3:3 │ 3 │ X0 Y0 Z0 │ ┌───╿──│──┘ │ ┌│───│──┘ │ ┏││━━━┙ │ ┃││ 4 │ ┃││ X1 Y1 Z1 5 │ ┃││ X2 Y2 Z2 │ ┃│└────╿──│──┘ `Z` label │ ┃└─────│──┤ │ ┗━━━━━━┥ `Y` is a good letter too │ `X` is a good letter ╰╴ note: bar ╭▸ test.rs:4:3 │ 4 │ ┏ X1 Y1 Z1 5 │ ┃ X2 Y2 Z2 6 │ ┃ X3 Y3 Z3 │ ┗━━━━━━━━━━┛ ├ note: bar ╰ note: baz note: qux ╭▸ test.rs:4:3 │ 4 │ X1 Y1 Z1 ╰╴ ━━━━━━━━ ``` Before: ``` error: foo --> test.rs:3:3 | 3 | X0 Y0 Z0 | ___^__-__- | |___|__| | ||___| | ||| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter | note: bar --> test.rs:4:3 | 4 | / X1 Y1 Z1 5 | | X2 Y2 Z2 6 | | X3 Y3 Z3 | |__________^ = note: bar = note: baz note: qux --> test.rs:4:3 | 4 | X1 Y1 Z1 | ^^^^^^^^ ``` After: ![rustc output with unicode box drawing characters](https://github.com/rust-lang/rust/assets/1606434/d210b79a-6579-4407-9706-ba8edc6e9f25) Before: ![current rustc output with ASCII art](https://github.com/rust-lang/rust/assets/1606434/5aecccf8-a6ee-4469-8b39-72fb0d979a9f)
2024-11-10Add Unicode block-drawing compiler output supportEsteban Küber-1/+6
Add nightly-only theming support to rustc output using Unicode box drawing characters instead of ASCII-art to draw the terminal UI: After: ``` error: foo ╭▸ test.rs:3:3 │ 3 │ X0 Y0 Z0 │ ┌───╿──│──┘ │ ┌│───│──┘ │ ┏││━━━┙ │ ┃││ 4 │ ┃││ X1 Y1 Z1 5 │ ┃││ X2 Y2 Z2 │ ┃│└────╿──│──┘ `Z` label │ ┃└─────│──┤ │ ┗━━━━━━┥ `Y` is a good letter too │ `X` is a good letter ╰╴ note: bar ╭▸ test.rs:4:3 │ 4 │ ┏ X1 Y1 Z1 5 │ ┃ X2 Y2 Z2 6 │ ┃ X3 Y3 Z3 │ ┗━━━━━━━━━━┛ ├ note: bar ╰ note: baz note: qux ╭▸ test.rs:4:3 │ 4 │ X1 Y1 Z1 ╰╴ ━━━━━━━━ ``` Before: ``` error: foo --> test.rs:3:3 | 3 | X0 Y0 Z0 | ___^__-__- | |___|__| | ||___| | ||| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter | note: bar --> test.rs:4:3 | 4 | / X1 Y1 Z1 5 | | X2 Y2 Z2 6 | | X3 Y3 Z3 | |__________^ = note: bar = note: baz note: qux --> test.rs:4:3 | 4 | X1 Y1 Z1 | ^^^^^^^^ ```
2024-10-28fix clippy::clone_on_ref_ptr for compilerklensy-2/+2
2024-10-07Convert `Option<&Lrc<T>>` return types to `Option<&T>`.Nicholas Nethercote-3/+3
It's simpler and more concise.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-4/+4
2024-09-12Implement a Method to Seal `DiagInner`'s SuggestionsVeera-3/+9
2024-08-08review commentsEsteban Küber-2/+2
2024-08-08Split `ColorConfig` off of `HumanReadableErrorType`Esteban Küber-3/+6
The previous setup tied two unrelated things together. Splitting these two is a better model.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-15/+17
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-26Clarify comment on changing to warn future breakage items Urgau-5/+5
https://github.com/rust-lang/rust/pull/120924/files#r1653512240
2024-06-25Prevent ICE from expected future breakagexFrednet-1/+6
2024-03-01If suggestion would leave an empty line, delete itclubby789-1/+11
2024-02-29Avoid unnecessary `color` local variable.Nicholas Nethercote-6/+3
2024-02-29Add a useful comment.Nicholas Nethercote-0/+1
It took me a while to work this out.
2024-02-29Make `JsonEmitter` more like `HumanEmitter`.Nicholas Nethercote-29/+19
Use `derive(Setters)` to derive setters, and then change `JsonEmitter::new` to only have the arguments that are always used.
2024-02-29Inline and remove `JsonEmitter::{basic,stderr}`.Nicholas Nethercote-55/+1
They are so similar to `JsonEmitter::new` it's not worth having separate functions, it makes the code harder to read.
2024-02-29Inline and remove `HumanReadableErrorType::new_emitter`.Nicholas Nethercote-3/+15
And likewise with `ColorConfig::suggests_using_colors`. They both have a single call site. And note that `BufWriter::supports_color()` always returns false, which enables a small bit of constant folding along the way.
2024-02-29Remove unnecessary `output` local variable.Nicholas Nethercote-5/+4
2024-02-29Simplify `UnusedExterns` lifetimes.Nicholas Nethercote-3/+3
In practice, 'a and 'b and 'c are always the same. This change makes `UnusedExterns` more like `ArtifactNotification`, which uses a single lifetime 'a in multiple ways.
2024-02-28Rename `SubDiagnostic` as `Subdiag`.Nicholas Nethercote-5/+5
Note the change of the `D` to `d`, to match all the other names that have `Subdiag` in them, such as `SubdiagnosticMessage` and `derive(Subdiagnostic)`.
2024-02-28Rename `Diagnostic` as `DiagInner`.Nicholas Nethercote-3/+3
I started by changing it to `DiagData`, but that didn't feel right. `DiagInner` felt much better.
2024-02-22Overhaul `Diagnostic` args.Nicholas Nethercote-1/+1
First, introduce a typedef `DiagnosticArgMap`. Second, make the `args` field public, and remove the `args` getter and `replace_args` setter. These were necessary previously because the getter had a `#[allow(rustc::potential_query_instability)]` attribute, but that was removed in #120931 when the args were changed from `FxHashMap` to `FxIndexMap`. (All the other `Diagnostic` fields are public.)
2024-02-05Make `Emitter::emit_diagnostic` consuming.Nicholas Nethercote-24/+28
All the other `emit`/`emit_diagnostic` methods were recently made consuming (e.g. #119606), but this one wasn't. But it makes sense to. Much of this is straightforward, and lots of `clone` calls are avoided. There are a couple of tricky bits. - `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and returns a pair. Instead it takes the two fields from `Diagnostic` that it used (`span` and `suggestions`) as `&mut`, and modifies them. This is necessary to avoid the cloning of `diag.children` in two emitters. - `from_errors_diagnostic` is rearranged so various uses of `diag` occur before the consuming `emit_diagnostic` call.
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-2/+2
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-14Rework how diagnostic lints are stored.Nicholas Nethercote-20/+17
`Diagnostic::code` has the type `DiagnosticId`, which has `Error` and `Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be redundant w.r.t. `Diagnostic::code`. Seems simple. Except it's possible for a lint to have an error code, in which case its `code` field is recorded as `Error`, and `is_lint` is required to indicate that it's a lint. This is what happens with `derive(LintDiagnostic)` lints. Which means those lints don't have a lint name or a `has_future_breakage` field because those are stored in the `DiagnosticId::Lint`. It's all a bit messy and confused and seems unintentional. This commit: - removes `DiagnosticId`; - changes `Diagnostic::code` to `Option<String>`, which means both errors and lints can straightforwardly have an error code; - changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a new type containing a lint name and a `has_future_breakage` bool, so all lints can have those, error code or not.
2024-01-11Change how `force-warn` lint diagnostics are recorded.Nicholas Nethercote-1/+1
`is_force_warn` is only possible for diagnostics with `Level::Warning`, but it is currently stored in `Diagnostic::code`, which every diagnostic has. This commit: - removes the boolean `DiagnosticId::Lint::is_force_warn` field; - adds a `ForceWarning` variant to `Level`. Benefits: - The common `Level::Warning` case now has no arguments, replacing lots of `Warning(None)` occurrences. - `rustc_session::lint::Level` and `rustc_errors::Level` are more similar, both having `ForceWarning` and `Warning`.
2023-12-23Remove `SubDiagnostic::render_span`.Nicholas Nethercote-5/+1
It's only ever set to `None`.
2023-12-23Improve some names.Nicholas Nethercote-2/+2
Lots of vectors of messages called `message` or `msg`. This commit pluralizes them. Note that `emit_message_default` and `emit_messages_default` both already existed, and both process a vector, so I renamed the former `emit_messages_default_inner` because it's called by the latter.
2023-11-20Update some more cases of "type" -> "$message_type"David Tolnay-1/+2
2023-10-13Use `$message_type` as the tagJeremy Fitzhardinge-1/+1
`type` turned out to be controversial.
2023-09-19Use serde_json::to_writer for JsonEmitter::emitJeremy Fitzhardinge-4/+5
Avoids an unnecessary intermediate string.
2023-09-19Make sure nested Diagnostics in FutureIncompat are also typed for consistency.Jeremy Fitzhardinge-7/+12
2023-09-19Add `type` field to json diagnostic outputsJeremy Fitzhardinge-24/+22
Currently the json-formatted outputs have no way to unambiguously determine which kind of message is being output. A consumer can look for specific fields in the json object (eg "message"), but there's no guarantee that in future some other kind of output will have a field of the same name. This PR adds a `"type"` field to add json outputs which can be used to unambiguously determine which kind of output it is. The mapping is: diagnostic: regular compiler diagnostics artifact: artifact notifications future_incompat: Report of future incompatibility unused_extern: Unused crate warnings/errors This matches the "internally tagged" representation for serde enums.
2023-09-15implement -Z ignore-directory-in-diagnostics-source-blocksPietro Albini-2/+14
2023-09-07Use `Freeze` for `SourceFile.external_src`John Kåre Alsaker-1/+1
2023-08-30Use conditional synchronization for LockJohn Kåre Alsaker-4/+4
2023-07-31Remove a `bool` for color in favor of the `WriteColor` trait wrapping ↵Oli Scherer-0/+14
colored and uncolored printing
2023-07-31Use builder pattern instead of lots of arguments for `EmitterWriter::new`Oli Scherer-11/+7
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-4/+4