about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics/utils.rs
AgeCommit message (Collapse)AuthorLines
2025-08-14cleanup: Remove useless `[T].iter().last()`Esteban Küber-1/+1
2025-02-22Fix binding mode problemsMichael Goulet-2/+2
2024-10-27give a better error for tuple structs in `derive(Diagnostic)`jyn-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-8/+9
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-05-21Add note_once/help_once to diagnostic derivesXiretza-0/+12
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-3/+3
`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-11-10Minor cleanups.Nicholas Nethercote-3/+3
- Reduce some function exposure. - Fix some comment formatting.
2023-06-23avoid `&format` in error message codeTakayuki Maeda-1/+1
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-9/+18
2023-05-08Make spans a bit betterMichael Goulet-0/+6
2023-05-08Diagnostic args are still args if they're documentedMichael Goulet-1/+2
2023-04-06address commentsDeadbeef-44/+49
2023-04-06fix errorsDeadbeef-1/+1
2023-04-06fix and bless ui tests 1/2Deadbeef-0/+13
2023-04-06migrate rustc_macros to syn 2.0Deadbeef-97/+89
2023-02-27Allow using `bool` for optional diagnosticsclubby789-0/+10
2023-02-01Forbid #[suggestion_*(...)] on VecsXiretza-30/+37
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-5/+3
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-10/+10
2022-11-18couple of clippy::perf fixesMatthias Krüger-1/+1
2022-10-26Remove #[suggestion_*] attributesXiretza-15/+37
2022-10-26Add "tool-only" suggestion styleXiretza-5/+8
2022-10-26Add style= parameter to suggestion attributesXiretza-14/+73
2022-10-23Allow specifying multiple alternative suggestionsXiretza-11/+94
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-17macros: support doc comments in diag derivesDavid Wood-3/+14
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: simplify field ordering in diag deriveDavid Wood-59/+1
Following the approach taken in earlier commits to separate formatting initialization from use in the subdiagnostic derive, simplify the diagnostic derive by removing the field-ordering logic that previously solved this problem. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10macros: separate suggestion fmt'ing and emissionDavid Wood-9/+39
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-09-26macros: support diagnostic derive on enumsDavid Wood-12/+73
Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-22Extract subdiagnostic attribute parsingXiretza-1/+255
2022-09-22Make SetOnce nicer to useXiretza-3/+11
2022-08-22Fix `build_format` not unescaping braces properlyfinalchild-27/+32
Co-authored-by: RanolP <public.ranolp@gmail.com>
2022-07-15macros: support `MultiSpan` in diag derivesDavid Wood-1/+7
Add support for `MultiSpan` with any of the attributes that work on a `Span` - requires that diagnostic logic generated for these attributes are emitted in the by-move block rather than the by-ref block that they would normally have been generated in. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05macros: add diagnostic derive for lintsDavid Wood-7/+13
`SessionDiagnostic` isn't suitable for use on lints as whether or not it creates an error or a warning is decided at compile-time by the macro, whereas lints decide this at runtime based on the location of the lint being reported (as it will depend on the user's `allow`/`deny` attributes, etc). Re-using most of the machinery for `SessionDiagnostic`, this macro introduces a `LintDiagnostic` derive which implements a `DecorateLint` trait, taking a `LintDiagnosticBuilder` and adding to the lint according to the diagnostic struct.
2022-07-05macros: introduce `build_field_mapping`David Wood-2/+19
Move the logic for building a field mapping (which is used by the building of format strings in `suggestion` annotations) into a helper function. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-19let `generate_field_attrs_code` create `FieldInfo`Christian Poveda-2/+1
this simplifies the code inside the `structure.each` closure argument and allows to remove the `vis` field from `FieldInfo`.
2022-05-12macros: spanless subdiagnostics from `()` fieldsDavid Wood-21/+33
Type attributes could previously be used to support spanless subdiagnostics but these couldn't easily be made optional in the same way that spanned subdiagnostics could by using a field attribute on a field with an `Option<Span>` type. Spanless subdiagnostics can now be specified on fields with `()` type or `Option<()>` type. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-06macros: allow `Vec` fields in diagnostic deriveDavid Wood-6/+55
Diagnostics can have multiple primary spans, or have subdiagnostics repeated at multiple locations, so support `Vec<..>` fields in the diagnostic derive which become loops in the generated code. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: allow setting applicability in attributeDavid Wood-0/+43
In the initial implementation of the `SessionSubdiagnostic`, the `Applicability` of a suggestion can be set both as a field and as part of the attribute, this commit adds the same support to the original `SessionDiagnostic` derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: add more documentation commentsDavid Wood-0/+3
Documentation comments are always good. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: split diagnostic derives into modulesDavid Wood-0/+221
Split `SessionDiagnostic` and `SessionSubdiagnostic` derives and the various helper functions into multiple modules. Signed-off-by: David Wood <david.wood@huawei.com>