about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
AgeCommit message (Collapse)AuthorLines
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-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`.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
2024-07-29Reformat `use` declarations.Nicholas Nethercote-6/+7
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/+4
2024-05-21Fix subdiagnostic-only enum variants not generating codeXiretza-2/+2
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-3/+3
For increased consistency. - session_diagnostic_derive -> diagnostic_derive - session_subdiagnostic_derive -> subdiagnostic_derive - SubdiagnosticDeriveBuilder -> SubdiagnosticDerive
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-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-1/+1
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-2/+2
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
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-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-4/+1
It avoids a lot of repetition.
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-7/+7
`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-19Remove unnecessary `use` items in derived `IntoDiagnostic` impls.Nicholas Nethercote-1/+0
Presumably these are a hangover from an earlier time when they were necessary.
2023-11-10Minor cleanups.Nicholas Nethercote-1/+1
- Reduce some function exposure. - Fix some comment formatting.
2023-10-13Format all the let chains in compilerMichael Goulet-1/+3
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-1/+3
2023-06-23avoid `&format` in error message codeTakayuki Maeda-1/+1
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-7/+16
2023-05-08Make spans a bit betterMichael Goulet-9/+12
2023-05-08Diagnostic args are still args if they're documentedMichael Goulet-7/+5
2023-04-06fix errorsDeadbeef-0/+1
2023-04-06migrate rustc_macros to syn 2.0Deadbeef-41/+37
2023-02-22errors: generate typed identifiers in each crateDavid Wood-1/+3
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-01Forbid #[suggestion_*(...)] on VecsXiretza-5/+16
It is ambiguous whether this should produce several `.span_suggestions()` calls or one `.multipart_suggestions()` call.
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-2/+1
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-1/+1
2022-12-01Remove useless borrows and derefsMaybe Waffle-2/+2
2022-10-23Allow specifying multiple alternative suggestionsXiretza-9/+12
This allows porting uses of span_suggestions() to diagnostic structs. Doesn't work for multipart_suggestions() because the rank would be reversed - the struct would specify multiple spans, each of which has multiple possible replacements, while multipart_suggestions() creates multiple possible replacements, each with multiple spans.
2022-10-17infer: use derive moreDavid Wood-0/+2
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17macros: fully specify path to `Fn`David Wood-1/+1
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17macros: allow subdiagnostic-kind-less variantsDavid Wood-5/+16
Sometimes it is convenient to return a subdiagnostic enum where one or more of the variants don't add anything to the diagnostic. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17macros: support doc comments in diag derivesDavid Wood-4/+18
Documentation comments shouldn't affect the diagnostic derive in any way, but explicit support has to be added for ignoring the `doc` attribute. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10macros: separate suggestion fmt'ing and emissionDavid Wood-12/+38
Diagnostic derives have previously had to take special care when ordering the generated code so that fields were not used after a move. This is unlikely for most fields because a field is either annotated with a subdiagnostic attribute and is thus likely a `Span` and copiable, or is a argument, in which case it is only used once by `set_arg` anyway. However, format strings for code in suggestions can result in fields being used after being moved if not ordered carefully. As a result, the derive currently puts `set_arg` calls last (just before emission), such as: ```rust let diag = { /* create diagnostic */ }; diag.span_suggestion_with_style( span, fluent::crate::slug, format!("{}", __binding_0), Applicability::Unknown, SuggestionStyle::ShowAlways ); /* + other subdiagnostic additions */ diag.set_arg("foo", __binding_0); /* + other `set_arg` calls */ diag.emit(); ``` For eager translation, this doesn't work, as the message being translated eagerly can assume that all arguments are available - so arguments _must_ be set first. Format strings for suggestion code are now separated into two parts - an initialization line that performs the formatting into a variable, and a usage in the subdiagnostic addition. By separating these parts, the initialization can happen before arguments are set, preserving the desired order so that code compiles, while still enabling arguments to be set before subdiagnostics are added. ```rust let diag = { /* create diagnostic */ }; let __code_0 = format!("{}", __binding_0); /* + other formatting */ diag.set_arg("foo", __binding_0); /* + other `set_arg` calls */ diag.span_suggestion_with_style( span, fluent::crate::slug, __code_0, Applicability::Unknown, SuggestionStyle::ShowAlways ); /* + other subdiagnostic additions */ diag.emit(); ``` Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10errors: `AddToDiagnostic::add_to_diagnostic_with`David Wood-17/+28
`AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure. Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-27Allow raw identifiers to be used as fluent argumentsXiretza-0/+3
2022-09-26macros: support diagnostic derive on enumsDavid Wood-19/+7
Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-22Better error recovery in Subdiagnostic deriveXiretza-20/+28
2022-09-22Extract subdiagnostic attribute parsingXiretza-231/+42
2022-09-22Make SetOnce nicer to useXiretza-13/+16
2022-09-21UPDATE - rename SessionSubdiagnostic macro to SubdiagnosticJhonny Bill Mena-9/+9
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21UPDATE - rename AddSubdiagnostic trait to AddToDiagnosticJhonny Bill Mena-1/+1
2022-09-01Allow deriving multiple subdiagnostics using one SessionSubdiagnosticXiretza-96/+120
This reimplements ac638c1, which had to be reverted in the previous commit because it contains a rebase accident that itself reverted significant unrelated changes to SessionSubdiagnostic.
2022-09-01Revert parts of "use derive proc macro to impl SessionDiagnostic"Xiretza-249/+445
This reverts parts of commit ac638c1f5fca36484506415319ab254ad522a692. During rebase, this commit accidentally reverted unrelated changes to the subdiagnostic derive (those allowing multipart_suggestions to be derived). This commit reverts all changes to the subdiagnostic code made in ac638c1f5fc, the next commit will reintroduce the actually intended changes.
2022-08-31use derive proc macro to impl SessionDiagnosticYuanheng Li-445/+249
fixes `SessionSubdiagnostic` to accept multiple attributes emitting list of fluent message remains unresolved
2022-08-30Rework SessionSubdiagnostic derive to support multipart_suggestionXiretza-219/+389
2022-08-30SessionSubdiagnostic: make `#[applicability]` optionalXiretza-8/+4