1
Fork 0

macros: add diagnostic derive for lints

`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.
This commit is contained in:
David Wood 2022-06-30 08:57:45 +01:00
parent 7f9d8480d6
commit 9d864c8d56
12 changed files with 847 additions and 614 deletions

View file

@ -127,6 +127,7 @@ decl_derive!(
// struct attributes
warning,
error,
lint,
note,
help,
// field attributes
@ -139,6 +140,24 @@ decl_derive!(
suggestion_hidden,
suggestion_verbose)] => diagnostics::session_diagnostic_derive
);
decl_derive!(
[LintDiagnostic, attributes(
// struct attributes
warning,
error,
lint,
note,
help,
// field attributes
skip_arg,
primary_span,
label,
subdiagnostic,
suggestion,
suggestion_short,
suggestion_hidden,
suggestion_verbose)] => diagnostics::lint_diagnostic_derive
);
decl_derive!(
[SessionSubdiagnostic, attributes(
// struct/variant attributes