about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics
AgeCommit message (Collapse)AuthorLines
2022-10-17macros: support doc comments in diag derivesDavid Wood-14/+60
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-102/+38
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-23/+81
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-10macros: `#[subdiagnostic(eager)]`David Wood-21/+63
Add support for `eager` argument to the `subdiagnostic` attribute which generates a call to `eager_subdiagnostic`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10errors: `AddToDiagnostic::add_to_diagnostic_with`David Wood-19/+30
`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-10-10macros: tidy up lint changesDavid Wood-3/+6
Small tweaks to changes made in a previous PR, unrelated to eager translation. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-03errors: rename `typeck.ftl` to `hir_analysis.ftl`David Wood-2/+2
In #102306, `rustc_typeck` was renamed to `rustc_hir_analysis` but the diagnostic resources were not renamed - which is what this commit changes. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-01Refactor rustc lint APIMaybe Waffle-15/+20
2022-09-27Allow raw identifiers to be used as fluent argumentsXiretza-0/+5
2022-09-26macros: support diagnostic derive on enumsDavid Wood-220/+252
Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-22Unify subdiagnostic attribute parsingXiretza-275/+139
2022-09-22Better error recovery in Subdiagnostic deriveXiretza-20/+28
2022-09-22Extract subdiagnostic attribute parsingXiretza-232/+297
2022-09-22Make SetOnce nicer to useXiretza-26/+39
2022-09-22Point to previous applicability when declared multiple timesXiretza-24/+11
2022-09-22Ensure #[suggestion] is only applied to correct tuple typesXiretza-33/+24
2022-09-22Ensure code= in #[suggestion(...)] is only set onceXiretza-2/+2
2022-09-22Cleanups in SessionDiagnostic deriveXiretza-11/+9
2022-09-21FIX - adopt new Diagnostic naming in newly migrated modulesJhonny Bill Mena-6/+6
FIX - ambiguous Diagnostic link in docs UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic [Gardening] FIX - formatting via `x fmt` FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way DELETE - unneeded allow attributes in Handler method FIX - broken test FIX - Rebase conflict UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21UPDATE - rename SessionSubdiagnostic macro to SubdiagnosticJhonny Bill Mena-14/+14
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21UPDATE - rename DiagnosticHandler macro to DiagnosticJhonny Bill Mena-8/+8
2022-09-21UPDATE - rename AddSubdiagnostic trait to AddToDiagnosticJhonny Bill Mena-1/+1
2022-09-21UPDATE - rename DiagnosticHandler trait to IntoDiagnosticJhonny Bill Mena-18/+18
2022-09-21UPDATE - move SessionDiagnostic from rustc_session to rustc_errorsJhonny Bill Mena-1/+1
2022-09-05UPDATE - into_diagnostic to take a Handler instead of a ParseSessJhonny Bill Mena-1/+1
Suggested by the team in this Zulip Topic https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if this is the best way to address this gap
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-31Rollup merge of #101165 - ldm0:drain_to_iter, r=cjgillotMatthias Krüger-1/+1
Use more `into_iter` rather than `drain(..)` Clearer semantic.
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
2022-08-30Use span_suggestion_with_style in SessionSubdiagnostic deriveXiretza-39/+65
2022-08-30Use more `into_iter` rather than `drain(..)`Donough Liu-1/+1
2022-08-24translations: rename warn_ to warningLuis Cardoso-16/+19
The macro warn_ was named like that because it the keyword warn is a built-in attribute and at the time this macro was created the word 'warning' was also taken. However it is no longer the case and we can rename warn_ to warning.
2022-08-23Auto merge of #100675 - Xiretza:fluent-mandate-crate-prefix, r=davidtwcobors-9/+21
fluent: mandate slug names to be prefixed by crate name This is currently only convention, but not actively checked for. Additionally, improve error messages to highlight the path of the offending fluent file rather than the identifier preceding it. This will conflict with #100671, so I'll leave it as draft until that's merged.
2022-08-22fluent: point to path containing error instead of module nameXiretza-5/+5
Example error before: error: name `generic_does_not_live_long_enough` does not start with the crate name --> compiler/rustc_error_messages/src/lib.rs:33:17 | 33 | borrowck => "../locales/en-US/borrowck.ftl", | ^^^^^^^^ | = help: prepend `borrowck_` to the slug name: `borrowck_generic_does_not_live_long_enough` after: error: name `generic_does_not_live_long_enough` does not start with the crate name --> compiler/rustc_error_messages/src/lib.rs:33:17 | 33 | borrowck => "../locales/en-US/borrowck.ftl", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: prepend `borrowck_` to the slug name: `borrowck_generic_does_not_live_long_enough`
2022-08-22fluent: mandate slug names to be prefixed by crate nameXiretza-5/+17
2022-08-22Fix `build_format` not unescaping braces properlyfinalchild-27/+32
Co-authored-by: RanolP <public.ranolp@gmail.com>
2022-08-21Replace #[lint/warning/error] with #[diag]Xiretza-17/+6
2022-08-21Disallow #[primary_span] on LintDiagnosticsXiretza-4/+13
2022-08-21Make derived SessionDiagnostics generic on diagnostic levelXiretza-105/+58
Deriving SessionDiagnostic on a type no longer forces that diagnostic to be one of warning, error, or fatal. The level is instead decided when the struct is passed to the respective Handler::emit_*() method.
2022-08-12Change fluent_messages macro to expect _ slugs instead of - slugsest31-5/+27
For the most part, the macro actually worked with _ slugs, but the prefix_something -> prefix::something conversion was not implemented. We don't want to accept - slugs for consistency reasons. We thus error if a name is found with - inside. This ensures a consistent style.
2022-08-12Update rustdoc to new slug styleest31-8/+8
2022-07-20clippy::perf fixesMatthias Krüger-4/+4
2022-07-15macros: support adding warnings to diagsDavid Wood-20/+43
Both diagnostic and subdiagnostic derives were missing the ability to add warnings to diagnostics - this is made more difficult by the `warn` attribute already existing, so this name being unavailable for the derives to use. `#[warn_]` is used instead, which requires special-casing so that `{span_,}warn` is called instead of `{span_,}warn_`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15macros: support `MultiSpan` in diag derivesDavid Wood-59/+88
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-08Use dashes instead of underscores in fluent namesMichael Goulet-2/+6
2022-07-05macros: add diagnostic derive for lintsDavid Wood-603/+768
`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: move `sess` out of builderDavid Wood-6/+4
`sess` field of `SessionDiagnosticDeriveBuilder` is never actually used in the builder's member functions, so it doesn't need to be a field. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05macros: introduce `build_field_mapping`David Wood-20/+22
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>