about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs
AgeCommit message (Collapse)AuthorLines
2022-08-30Use span_suggestion_with_style in SessionSubdiagnostic deriveXiretza-39/+65
2022-08-24translations: rename warn_ to warningLuis Cardoso-2/+2
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-07-15macros: support adding warnings to diagsDavid Wood-0/+4
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-05macros: add diagnostic derive for lintsDavid Wood-5/+4
`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-06-24macros: use typed identifiers in subdiag deriveDavid Wood-12/+72
As in the diagnostic derive, using typed identifiers in the subdiagnostic derive improves the diagnostics of using the subdiagnostic derive as Fluent messages will be confirmed to exist at compile-time. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-30errors: simplify referring to fluent attributesDavid Wood-1/+1
To render the message of a Fluent attribute, the identifier of the Fluent message must be known. `DiagnosticMessage::FluentIdentifier` contains both the message's identifier and optionally the identifier of an attribute. Generated constants for each attribute would therefore need to be named uniquely (amongst all error messages) or be able to refer to only the attribute identifier which will be combined with a message identifier later. In this commit, the latter strategy is implemented as part of the `Diagnostic` type's functions for adding subdiagnostics of various kinds. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-19let `generate_field_attrs_code` create `FieldInfo`Christian Poveda-1/+0
this simplifies the code inside the `structure.each` closure argument and allows to remove the `vis` field from `FieldInfo`.
2022-05-12errors: `set_arg` takes `IntoDiagnosticArg`David Wood-1/+1
Manual implementors of translatable diagnostics will need to call `set_arg`, not just the derive, so make this function a bit more ergonomic by taking `IntoDiagnosticArg` rather than `DiagnosticArgValue`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-06macros: allow `Vec` fields in diagnostic deriveDavid Wood-13/+5
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-43/+1
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/+9
Documentation comments are always good. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: add helper functions for invalid attrsDavid Wood-80/+20
Remove some duplicated code between both diagnostic derives by introducing helper functions for reporting an error in case of a invalid attribute. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: split diagnostic derives into modulesDavid Wood-0/+530
Split `SessionDiagnostic` and `SessionSubdiagnostic` derives and the various helper functions into multiple modules. Signed-off-by: David Wood <david.wood@huawei.com>