summary refs log tree commit diff
path: root/compiler/rustc_errors/src/emitter.rs
AgeCommit message (Collapse)AuthorLines
2024-03-14Rollup merge of #120699 - nnethercote:rm-useless-TRACK_DIAGNOSTIC-calls, ↵Matthias Krüger-1/+1
r=oli-obk Document `TRACK_DIAGNOSTIC` calls. r? ```````@cjgillot```````
2024-03-05errors: share `SilentEmitter` between rustc and rustfmtDavid Wood-24/+8
Signed-off-by: David Wood <david@davidtw.co>
2024-03-05Rename `DiagnosticMessage` as `DiagMessage`.Nicholas Nethercote-11/+9
2024-03-01Make the `match` in `emit_diagnostic` complete.Nicholas Nethercote-1/+1
This match is complex enough that it's a good idea to enumerate every variant. This also means `can_be_top_or_sub` can just be `can_be_subdiag`.
2024-02-29Make `JsonEmitter` more like `HumanEmitter`.Nicholas Nethercote-2/+1
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 `HumanEmitter::stderr`.Nicholas Nethercote-5/+1
Because `HumanEmitter::new` is enough, in conjunction with the (renamed) `stderr_destination` function.
2024-02-29Inline and remove `HumanReadableErrorType::new_emitter`.Nicholas Nethercote-19/+1
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-29Merge HumanEmitter::{new,create}.Nicholas Nethercote-7/+2
They have the same signature, and the former just calls the latter.
2024-02-29Use `Destination` more.Nicholas Nethercote-6/+3
2024-02-29Minor visibility and formatting improvements.Nicholas Nethercote-9/+11
2024-02-28Rename `DiagnosticLocation` as `DiagLocation`.Nicholas Nethercote-4/+4
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-1/+1
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-28Rename `SubDiagnostic` as `Subdiag`.Nicholas Nethercote-12/+8
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-7/+7
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-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-1/+1
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-17Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercoteMatthias Krüger-0/+23
errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). r? ```@nnethercote```
2024-02-15Rollup merge of #121107 - estebank:capitalization-suggestion, r=michaelwoeristerGuillaume Gomez-9/+10
Fix msg for verbose suggestions with confusable capitalization When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions). The logic to do this was already present, but implemented incorrectly.
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-0/+23
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
2024-02-14Fix msg for verbose suggestions with confusable capitalizationEsteban Küber-9/+10
When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions). The logic to do this was already present, but implemented incorrectly.
2024-02-13Bump `indexmap`clubby789-1/+2
`swap` has been deprecated in favour of `swap_remove` - the behaviour is the same though.
2024-02-06Rollup merge of #120575 - nnethercote:simplify-codegen-diag-handling, r=estebankMatthias Krüger-22/+19
Simplify codegen diagnostic handling Some nice improvements. Details in the individual commit logs. r? ````@estebank````
2024-02-05Make `Emitter::emit_diagnostic` consuming.Nicholas Nethercote-22/+19
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-02-05Split `Level::DelayedBug` in two.Nicholas Nethercote-0/+1
The two kinds of delayed bug have quite different semantics so a stronger conceptual separation is nice. (`is_error` is a good example, because the two kinds have different behaviour.) The commit also moves the `DelayedBug` variant after `Error` in `Level`, to reflect the fact that it's weaker than `Error` -- it might trigger an error but also might not. (The pre-existing `downgrade_to_delayed_bug` function also reflects the notion that delayed bugs are lower/after normal errors.) Plus it condenses some of the comments on `Level` into a table, for easier reading, and introduces `can_be_top_or_sub` to indicate which levels can be used in top-level diagnostics vs. subdiagnostics. Finally, it renames `DiagCtxtInner::span_delayed_bugs` as `DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because some delayed bugs don't have a span.
2024-02-03`SilentEmitter::fatal_note` doesn't need to be optional.Nicholas Nethercote-8/+6
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-6/+6
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-9/+8
`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-05Add some comments to `Emitter`.Nicholas Nethercote-3/+5
There are three functions only used for the JSON format.
2024-01-05Rename `EmitterWriter` as `HumanEmitter`.Nicholas Nethercote-10/+10
For consistency with other `Emitter` impls, such as `JsonEmitter`, `SilentEmitter`, `SharedEmitter`, etc.
2023-12-23Remove `SubDiagnostic::render_span`.Nicholas Nethercote-2/+1
It's only ever set to `None`.
2023-12-23Improve some names.Nicholas Nethercote-17/+17
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-12-18Rename `SilentEmitter::fatal_handler` as `SilentEmitter::fatal_dcx`.Nicholas Nethercote-3/+3
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-3/+3
2023-12-15use `if cfg` instead of `#[cfg]`jyn-4/+1
this pr is specifically for waffle because i love it <3
2023-12-15Split `Handler::emit_diagnostic` in two.Nicholas Nethercote-1/+1
Currently, `emit_diagnostic` takes `&mut self`. This commit changes it so `emit_diagnostic` takes `self` and the new `emit_diagnostic_without_consuming` function takes `&mut self`. I find the distinction useful. The former case is much more common, and avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the latter with `pub(crate)` which is nice.
2023-12-08use magenta instead of bold for highlightingjyn-1/+1
according to a poll of gay people in my phone, purple is the most popular color to use for highlighting | color | percentage | | ---------- | ---------- | | bold white | 6% | | blue | 14% | | cyan | 26% | | purple | 37% | | magenta | 17% | unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason. until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it. instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty.
2023-12-08Simplify and comment the special-casing for Windows colorsjyn-10/+10
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-4/+4
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-08rustc: minor changes suggested by clippy perf lints.Nicholas Nethercote-5/+1
2023-10-20Auto merge of #116962 - estebank:issue-63835, r=oli-obkbors-1/+8
Do not bold main message in `--error-format=short` Fix #63835. Before: <img width="484" alt="Screenshot 2023-10-19 at 3 52 53 PM" src="https://github.com/rust-lang/rust/assets/1606434/9bd6cbd5-a4ce-4cc3-8c5f-60a8d3ad38da"> After: <img width="492" alt="Screenshot 2023-10-19 at 3 52 32 PM" src="https://github.com/rust-lang/rust/assets/1606434/0cf2417a-08f2-4074-860c-a88a838a4209">
2023-10-19Do not bold main message in `--error-format=short`Esteban Küber-1/+8
Fix #63835.
2023-10-19Fix duplicate labels emitted in `render_multispan_macro_backtrace()`Gurinder Singh-4/+4
Using hash set instead of vec to weed out duplicates
2023-10-13Format all the let chains in compilerMichael Goulet-4/+4
2023-09-15implement -Z ignore-directory-in-diagnostics-source-blocksPietro Albini-3/+24
2023-09-07Use `Freeze` for `SourceFile.external_src`John Kåre Alsaker-2/+2
2023-09-04Auto merge of #115513 - Urgau:normalize-msg-after-translate, r=petrochenkovbors-1/+7
Don't forget to normalize the translated message This PR adds a missing call to `normalize_whitespace` after translating an label. Fixes https://github.com/rust-lang/rust/issues/115498
2023-09-03Don't forget to normalize the translated messageUrgau-1/+7
2023-08-30Use conditional synchronization for LockJohn Kåre Alsaker-3/+5
2023-07-31Sanity check that we actually flush all buffersOli Scherer-0/+9
2023-07-31Get rid of the thin wrapper type that is `Destination` and just write to the ↵Oli Scherer-32/+19
`Writer` trait object directly