Skip to content

Commit e6cd5f6

Browse files
committed
Move out from #[derive(LintDiagnostic)] to manual impl
1 parent 4fd98a4 commit e6cd5f6

File tree

2 files changed

+71
-17
lines changed

2 files changed

+71
-17
lines changed

compiler/rustc_lint/src/lints.rs

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,40 +1333,95 @@ pub struct SuspiciousDoubleRefCloneDiag<'a> {
13331333
}
13341334

13351335
// non_local_defs.rs
1336-
#[derive(LintDiagnostic)]
13371336
pub enum NonLocalDefinitionsDiag {
1338-
#[diag(lint_non_local_definitions_impl)]
1339-
#[help]
1340-
#[note(lint_non_local)]
1341-
#[note(lint_exception)]
1342-
#[note(lint_non_local_definitions_deprecation)]
13431337
Impl {
13441338
depth: u32,
13451339
body_kind_descr: &'static str,
13461340
body_name: String,
1347-
#[subdiagnostic]
13481341
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1349-
#[suggestion(lint_const_anon, code = "_", applicability = "machine-applicable")]
13501342
const_anon: Option<Span>,
13511343
},
1352-
#[diag(lint_non_local_definitions_macro_rules)]
13531344
MacroRules {
13541345
depth: u32,
13551346
body_kind_descr: &'static str,
13561347
body_name: String,
1357-
#[help]
13581348
help: Option<()>,
1359-
#[help(lint_help_doctest)]
13601349
doctest_help: Option<()>,
1361-
#[note(lint_non_local)]
1362-
#[note(lint_exception)]
1363-
#[note(lint_non_local_definitions_deprecation)]
1364-
notes: (),
1365-
#[subdiagnostic]
13661350
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
13671351
},
13681352
}
13691353

1354+
impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
1355+
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
1356+
match self {
1357+
NonLocalDefinitionsDiag::Impl {
1358+
depth,
1359+
body_kind_descr,
1360+
body_name,
1361+
cargo_update,
1362+
const_anon,
1363+
} => {
1364+
diag.arg("depth", depth);
1365+
diag.arg("body_kind_descr", body_kind_descr);
1366+
diag.arg("body_name", body_name);
1367+
1368+
diag.help(fluent::lint_help);
1369+
diag.note(fluent::lint_non_local);
1370+
diag.note(fluent::lint_exception);
1371+
diag.note(fluent::lint_non_local_definitions_deprecation);
1372+
1373+
if let Some(cargo_update) = cargo_update {
1374+
diag.subdiagnostic(&diag.dcx, cargo_update);
1375+
}
1376+
if let Some(const_anon) = const_anon {
1377+
diag.span_suggestion(
1378+
const_anon,
1379+
fluent::lint_const_anon,
1380+
"_",
1381+
Applicability::MachineApplicable,
1382+
);
1383+
}
1384+
}
1385+
NonLocalDefinitionsDiag::MacroRules {
1386+
depth,
1387+
body_kind_descr,
1388+
body_name,
1389+
help,
1390+
doctest_help,
1391+
cargo_update,
1392+
} => {
1393+
diag.arg("depth", depth);
1394+
diag.arg("body_kind_descr", body_kind_descr);
1395+
diag.arg("body_name", body_name);
1396+
1397+
if let Some(()) = help {
1398+
diag.help(fluent::lint_help);
1399+
}
1400+
if let Some(()) = doctest_help {
1401+
diag.help(fluent::lint_help_doctest);
1402+
}
1403+
1404+
diag.note(fluent::lint_non_local);
1405+
diag.note(fluent::lint_exception);
1406+
diag.note(fluent::lint_non_local_definitions_deprecation);
1407+
1408+
if let Some(cargo_update) = cargo_update {
1409+
diag.subdiagnostic(&diag.dcx, cargo_update);
1410+
}
1411+
}
1412+
}
1413+
}
1414+
1415+
fn msg(&self) -> DiagMessage {
1416+
match self {
1417+
NonLocalDefinitionsDiag::Impl { .. } => fluent::lint_non_local_definitions_impl,
1418+
NonLocalDefinitionsDiag::MacroRules { .. } => {
1419+
fluent::lint_non_local_definitions_macro_rules
1420+
}
1421+
}
1422+
}
1423+
}
1424+
13701425
#[derive(Subdiagnostic)]
13711426
#[note(lint_non_local_definitions_cargo_update)]
13721427
pub struct NonLocalDefinitionsCargoUpdateNote {

compiler/rustc_lint/src/non_local_def.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
250250
cargo_update: cargo_update(),
251251
help: (!is_at_toplevel_doctest).then_some(()),
252252
doctest_help: is_at_toplevel_doctest.then_some(()),
253-
notes: (),
254253
},
255254
)
256255
}

0 commit comments

Comments
 (0)