non_local_defs: move out from #[derive(LintDiagnostic)] to manual impl

This commit is contained in:
Urgau 2024-05-13 19:35:52 +02:00
parent f00b02e6bb
commit 5ad4ad7aee
2 changed files with 64 additions and 17 deletions

View File

@ -1329,40 +1329,88 @@ pub struct SuspiciousDoubleRefCloneDiag<'a> {
} }
// non_local_defs.rs // non_local_defs.rs
#[derive(LintDiagnostic)]
pub enum NonLocalDefinitionsDiag { pub enum NonLocalDefinitionsDiag {
#[diag(lint_non_local_definitions_impl)]
#[help]
#[note(lint_non_local)]
#[note(lint_exception)]
#[note(lint_non_local_definitions_deprecation)]
Impl { Impl {
depth: u32, depth: u32,
body_kind_descr: &'static str, body_kind_descr: &'static str,
body_name: String, body_name: String,
#[subdiagnostic]
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>, cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
#[suggestion(lint_const_anon, code = "_", applicability = "machine-applicable")]
const_anon: Option<Span>, const_anon: Option<Span>,
}, },
#[diag(lint_non_local_definitions_macro_rules)]
MacroRules { MacroRules {
depth: u32, depth: u32,
body_kind_descr: &'static str, body_kind_descr: &'static str,
body_name: String, body_name: String,
#[help]
help: Option<()>, help: Option<()>,
#[help(lint_help_doctest)]
doctest_help: Option<()>, doctest_help: Option<()>,
#[note(lint_non_local)]
#[note(lint_exception)]
#[note(lint_non_local_definitions_deprecation)]
notes: (),
#[subdiagnostic]
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>, 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)] #[derive(Subdiagnostic)]
#[note(lint_non_local_definitions_cargo_update)] #[note(lint_non_local_definitions_cargo_update)]
pub struct NonLocalDefinitionsCargoUpdateNote { pub struct NonLocalDefinitionsCargoUpdateNote {

View File

@ -250,7 +250,6 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
cargo_update: cargo_update(), cargo_update: cargo_update(),
help: (!is_at_toplevel_doctest).then_some(()), help: (!is_at_toplevel_doctest).then_some(()),
doctest_help: is_at_toplevel_doctest.then_some(()), doctest_help: is_at_toplevel_doctest.then_some(()),
notes: (),
}, },
) )
} }