diff options
| author | Urgau <urgau@numericable.fr> | 2024-05-13 19:35:52 +0200 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2024-05-27 23:58:55 +0200 |
| commit | 5ad4ad7aee5e0e63d8a2d95fd5dabf194e56836b (patch) | |
| tree | 305f888f09e9cf3313110f39286be1f7fd28dfea /compiler/rustc_lint/src/lints.rs | |
| parent | f00b02e6bbe63707503f058fb87cc3e2b25991ac (diff) | |
| download | rust-5ad4ad7aee5e0e63d8a2d95fd5dabf194e56836b.tar.gz rust-5ad4ad7aee5e0e63d8a2d95fd5dabf194e56836b.zip | |
non_local_defs: move out from `#[derive(LintDiagnostic)]` to manual impl
Diffstat (limited to 'compiler/rustc_lint/src/lints.rs')
| -rw-r--r-- | compiler/rustc_lint/src/lints.rs | 80 |
1 files changed, 64 insertions, 16 deletions
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 42963a11f71..deaf56c8f25 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1329,40 +1329,88 @@ pub struct SuspiciousDoubleRefCloneDiag<'a> { } // non_local_defs.rs -#[derive(LintDiagnostic)] pub enum NonLocalDefinitionsDiag { - #[diag(lint_non_local_definitions_impl)] - #[help] - #[note(lint_non_local)] - #[note(lint_exception)] - #[note(lint_non_local_definitions_deprecation)] Impl { depth: u32, body_kind_descr: &'static str, body_name: String, - #[subdiagnostic] cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>, - #[suggestion(lint_const_anon, code = "_", applicability = "machine-applicable")] const_anon: Option<Span>, }, - #[diag(lint_non_local_definitions_macro_rules)] MacroRules { depth: u32, body_kind_descr: &'static str, body_name: String, - #[help] help: Option<()>, - #[help(lint_help_doctest)] doctest_help: Option<()>, - #[note(lint_non_local)] - #[note(lint_exception)] - #[note(lint_non_local_definitions_deprecation)] - notes: (), - #[subdiagnostic] cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>, }, } +impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag { + fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) { + match self { + NonLocalDefinitionsDiag::Impl { + depth, + body_kind_descr, + body_name, + cargo_update, + const_anon, + } => { + diag.primary_message(fluent::lint_non_local_definitions_impl); + diag.arg("depth", depth); + diag.arg("body_kind_descr", body_kind_descr); + diag.arg("body_name", body_name); + + diag.help(fluent::lint_help); + diag.note(fluent::lint_non_local); + diag.note(fluent::lint_exception); + diag.note(fluent::lint_non_local_definitions_deprecation); + + if let Some(cargo_update) = cargo_update { + diag.subdiagnostic(&diag.dcx, cargo_update); + } + if let Some(const_anon) = const_anon { + diag.span_suggestion( + const_anon, + fluent::lint_const_anon, + "_", + Applicability::MachineApplicable, + ); + } + } + NonLocalDefinitionsDiag::MacroRules { + depth, + body_kind_descr, + body_name, + help, + doctest_help, + cargo_update, + } => { + diag.primary_message(fluent::lint_non_local_definitions_macro_rules); + diag.arg("depth", depth); + diag.arg("body_kind_descr", body_kind_descr); + diag.arg("body_name", body_name); + + if let Some(()) = help { + diag.help(fluent::lint_help); + } + if let Some(()) = doctest_help { + diag.help(fluent::lint_help_doctest); + } + + diag.note(fluent::lint_non_local); + diag.note(fluent::lint_exception); + diag.note(fluent::lint_non_local_definitions_deprecation); + + if let Some(cargo_update) = cargo_update { + diag.subdiagnostic(&diag.dcx, cargo_update); + } + } + } + } +} + #[derive(Subdiagnostic)] #[note(lint_non_local_definitions_cargo_update)] pub struct NonLocalDefinitionsCargoUpdateNote { |
