diff options
| author | David Wood <david.wood@huawei.com> | 2022-06-30 08:57:45 +0100 | 
|---|---|---|
| committer | David Wood <david.wood@huawei.com> | 2022-07-05 16:00:21 +0100 | 
| commit | 9d864c8d56fee09abae2be2bed1d4dc1a86b457b (patch) | |
| tree | 2a579870a01f5273c26b34f2f3d567e3c9b6b3e5 /compiler/rustc_macros/src/diagnostics/subdiagnostic.rs | |
| parent | 7f9d8480d665b8dcc7b1359372e394d455b6e29a (diff) | |
| download | rust-9d864c8d56fee09abae2be2bed1d4dc1a86b457b.tar.gz rust-9d864c8d56fee09abae2be2bed1d4dc1a86b457b.zip | |
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.
Diffstat (limited to 'compiler/rustc_macros/src/diagnostics/subdiagnostic.rs')
| -rw-r--r-- | compiler/rustc_macros/src/diagnostics/subdiagnostic.rs | 9 | 
1 files changed, 4 insertions, 5 deletions
| diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index eab954a9c1b..2a5b6beba94 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -1,8 +1,7 @@ #![deny(unused_must_use)] use crate::diagnostics::error::{ - span_err, throw_invalid_attr, throw_invalid_nested_attr, throw_span_err, - SessionDiagnosticDeriveError, + span_err, throw_invalid_attr, throw_invalid_nested_attr, throw_span_err, DiagnosticDeriveError, }; use crate::diagnostics::utils::{ report_error_if_not_applied_to_applicability, report_error_if_not_applied_to_span, @@ -214,7 +213,7 @@ impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> { } impl<'a> SessionSubdiagnosticDeriveBuilder<'a> { - fn identify_kind(&mut self) -> Result<(), SessionDiagnosticDeriveError> { + fn identify_kind(&mut self) -> Result<(), DiagnosticDeriveError> { for attr in self.variant.ast().attrs { let span = attr.span().unwrap(); @@ -351,7 +350,7 @@ impl<'a> SessionSubdiagnosticDeriveBuilder<'a> { &mut self, binding: &BindingInfo<'_>, is_suggestion: bool, - ) -> Result<TokenStream, SessionDiagnosticDeriveError> { + ) -> Result<TokenStream, DiagnosticDeriveError> { let ast = binding.ast(); let inner_ty = FieldInnerTy::from_type(&ast.ty); @@ -411,7 +410,7 @@ impl<'a> SessionSubdiagnosticDeriveBuilder<'a> { Ok(inner_ty.with(binding, generated)) } - fn into_tokens(&mut self) -> Result<TokenStream, SessionDiagnosticDeriveError> { + fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> { self.identify_kind()?; let Some(kind) = self.kind.map(|(kind, _)| kind) else { throw_span_err!( | 
