Skip to content

Commit 2921572

Browse files
committed
Move out from #[derive(LintDiagnostic)] to manual impl
1 parent 54cdc13 commit 2921572

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
@@ -1340,40 +1340,95 @@ pub struct SuspiciousDoubleRefCloneDiag<'a> {
13401340
}
13411341

13421342
// non_local_defs.rs
1343-
#[derive(LintDiagnostic)]
13441343
pub enum NonLocalDefinitionsDiag {
1345-
#[diag(lint_non_local_definitions_impl)]
1346-
#[help]
1347-
#[note(lint_non_local)]
1348-
#[note(lint_exception)]
1349-
#[note(lint_non_local_definitions_deprecation)]
13501344
Impl {
13511345
depth: u32,
13521346
body_kind_descr: &'static str,
13531347
body_name: String,
1354-
#[subdiagnostic]
13551348
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
1356-
#[suggestion(lint_const_anon, code = "_", applicability = "machine-applicable")]
13571349
const_anon: Option<Span>,
13581350
},
1359-
#[diag(lint_non_local_definitions_macro_rules)]
13601351
MacroRules {
13611352
depth: u32,
13621353
body_kind_descr: &'static str,
13631354
body_name: String,
1364-
#[help]
13651355
help: Option<()>,
1366-
#[help(lint_help_doctest)]
13671356
doctest_help: Option<()>,
1368-
#[note(lint_non_local)]
1369-
#[note(lint_exception)]
1370-
#[note(lint_non_local_definitions_deprecation)]
1371-
notes: (),
1372-
#[subdiagnostic]
13731357
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
13741358
},
13751359
}
13761360

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