about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics
AgeCommit message (Collapse)AuthorLines
2025-08-14cleanup: Remove useless `[T].iter().last()`Esteban Küber-1/+1
2025-06-26Only args in main diag are saved and restored without removing the newly ↵xizheyin-11/+5
added ones Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-25Add runtime check to avoid overwrite arg easily in diag and store and ↵xizheyin-5/+25
restore snapshot when set subdiag arg Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-23Remove `synstructure::Structure::underscore_const` calls.Nicholas Nethercote-6/+3
The `synstructure` docs say "This method is a no-op, underscore consts are used by default now." The behaviour change occurred going from `synstructure` version 0.13.0 to 0.13.1.
2025-04-16Move eager translation to a method on `Diag`Jake Goulding-11/+4
This will allow us to eagerly translate messages on a top-level diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the awkward closure passed into Subdiagnostic and make better use of `Into`.
2025-02-22Fix binding mode problemsMichael Goulet-2/+2
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-1/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-10-27give a better error for tuple structs in `derive(Diagnostic)`jyn-3/+6
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-13/+13
2024-08-29Add `warn(unreachable_pub)` to `rustc_macros`.Nicholas Nethercote-3/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-25/+29
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-14Suppress some fallout from gen in synstructureMichael Goulet-0/+8
2024-07-10Make sure that labels are defined after the primary span in diagnosticsMichael Goulet-0/+9
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-1/+1
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-1/+1
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-20/+12
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-23Slightly clean up some lint infra codeLeón Orell Valerian Liehr-1/+1
* inline `LintBuffer::add_lint`, it only had a single use * update a lint infra example code snippet * it used the wrong API (the snippet isn't tested) * presumably the arguments were updated from builder to diag struct style at some point without updating the method
2024-05-21Fix subdiagnostic-only enum variants not generating codeXiretza-2/+2
2024-05-21Add note_once/help_once to diagnostic derivesXiretza-4/+24
2024-04-21Allow nesting subdiagnosticsXiretza-12/+25
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-1/+1
2024-03-11Rename diagnostic derive things.Nicholas Nethercote-7/+7
For increased consistency. - session_diagnostic_derive -> diagnostic_derive - session_subdiagnostic_derive -> subdiagnostic_derive - SubdiagnosticDeriveBuilder -> SubdiagnosticDerive
2024-03-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-1/+1
To match `derive(LintDiagnostic)`.
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-3/+3
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-6/+3
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-1/+1
2024-03-05Rename `DiagnosticMessage` as `DiagMessage`.Nicholas Nethercote-1/+1
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-6/+6
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-25Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkinbors-3/+6
Implement RFC 3373: Avoid non-local definitions in functions This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-3/+7
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-17Make synstructure underscore_const(true) the defaultUrgau-3/+6
since otherwise it will trigger the non_local_definitions lint
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-38/+1
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-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-4/+1
It avoids a lot of repetition.
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-3/+3
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-23Rename `LintContext::struct_span_lint` as `LintContext::span_lint`.Nicholas Nethercote-1/+1
2024-01-14Rework how diagnostic lints are stored.Nicholas Nethercote-1/+1
`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-03Rename some `Diagnostic` setters.Nicholas Nethercote-19/+19
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-2/+7
And make all hand-written `IntoDiagnostic` impls generic, by using `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g. `dcx.struct_err(...)`. This means the `create_*` functions are the source of the error level. This change will let us remove `struct_diagnostic`. Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`, it's necessary to pass diagnostics tests now that it's used in `into_diagnostic` functions.
2023-12-19Streamline `Diagnostic` proc macro.Nicholas Nethercote-83/+45
First, it is parameterized by the name of the diagnostic and the DiagCtxt. These are given to `session_diagnostic_derive` and `lint_diagnostic_derive`. But the names are hard-wired as "diag" and "handler" (should be "dcx"), and there's no clear reason for the parameterization. So this commit removes the parameterization and hard-wires the names internally. Once that is done `DiagnosticDeriveBuilder` is reduced to a trivial wrapper around `DiagnosticDeriveKind`, and can be removed. Also, `DiagnosticDerive` and `LintDiagnosticDerive` don't need the `builder` field, because it has been reduced to a kind, and they know their own kind. This avoids the need for some `let`/`else`/`unreachable!` kind checks And `DiagnosticDeriveVariantBuilder` no longer needs a lifetime, because the `parent` field is changed to `kind`, which is now a trivial copy type.
2023-12-19Remove unnecessary `use` items in derived `IntoDiagnostic` impls.Nicholas Nethercote-3/+0
Presumably these are a hangover from an earlier time when they were necessary.
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-2/+2
2023-12-18Rename `__diagnostic_handler_sess` as `_sess`.Nicholas Nethercote-4/+5
2023-12-18Rename `DiagnosticDeriveKind::Diagnostic::handler` as ↵Nicholas Nethercote-10/+10
`DiagnosticDeriveKind::Diagnostic::dcx`.
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-1/+1
2023-12-16Simplify lint decorator derive tooMichael Goulet-2/+2
2023-11-10Minor cleanups.Nicholas Nethercote-9/+10
- Reduce some function exposure. - Fix some comment formatting.
2023-10-13Format all the let chains in compilerMichael Goulet-19/+23
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-5/+13
2023-06-28Auto merge of #111269 - clubby789:validate-fluent-variables, r=davidtwcobors-4/+57
Validate fluent variable references in tests Closes #101109 Under `cfg(test)`, the `fluent_messages` macro will emit a list of variables referenced by each message and its attributes. The derive attribute will now emit a `#[test]` that checks that each referenced variable exists in the structure it's applied to.
2023-06-23avoid `&format` in error message codeTakayuki Maeda-8/+6