about summary refs log tree commit diff
path: root/compiler/rustc_errors/src/json.rs
AgeCommit message (Collapse)AuthorLines
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
2023-02-26refactor: statically guarantee that current error codes are documentedEzra Shaw-1/+1
2023-02-09Introduce `-Zterminal-urls` to use OSC8 for error codesEsteban Küber-0/+9
Terminals supporting the OSC8 Hyperlink Extension can support inline anchors where the text is user defineable but clicking on it opens a browser to a specified URLs, just like `<a href="URL">` does in HTML. https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
2023-01-08Make translate_message return result and add testsmejrs-2/+7
2022-12-01Remove useless borrows and derefsMaybe Waffle-1/+1
2022-10-19Implement -Ztrack-diagnosticsmejrs-0/+8
2022-10-10errors: use `HashMap` to store diagnostic argsDavid Wood-2/+2
Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-08-15errors: move translation logic into moduleDavid Wood-8/+11
Just moving code around so that triagebot can ping relevant parties when translation logic is modified. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-06session: `output-width` -> `diagnostic-width`David Wood-8/+8
Rename the `--output-width` flag to `--diagnostic-width` as this appears to be the preferred name within the compiler team. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-06session: `terminal-width` -> `output-width`David Wood-8/+8
Rename the `--terminal-width` flag to `--output-width` as the behaviour doesn't just apply to terminals (and so is slightly less accurate). Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-16Support lint expectations for `--force-warn` lints (RFC 2383)xFrednet-1/+1
2022-06-03Use serde_json for json error messagesbjorn3-18/+18
2022-04-27Plumb through rustc_lint_defs::Level as enum rather than string.Jeremy Fitzhardinge-1/+2
2022-04-15Remove `--extern-location` and all associated codeJeremy Fitzhardinge-66/+1
`--extern-location` was an experiment to investigate the best way to generate useful diagnostics for unused dependency warnings by enabling a build system to identify the corresponding build config. While I did successfully use this, I've since been convinced the alternative `--json unused-externs` mechanism is the way to go, and there's no point in having two mechanisms with basically the same functionality. This effectively reverts https://github.com/rust-lang/rust/pull/72603
2022-04-13errors: lazily load fallback fluent bundleDavid Wood-7/+9
Loading the fallback bundle in compilation sessions that won't go on to emit any errors unnecessarily degrades compile time performance, so lazily create the Fluent bundle when it is first required. Signed-off-by: David Wood <david.wood@huawei.com>