Skip to content

Commit 33faf01

Browse files
committed
Eliminate four unnecessary lint macros.
The lint definitions use macros heavily. This commit merges some of them that are split unnecessarily. I find the reduced indirection makes it easier to imagine what the generated code will look like.
1 parent c090c68 commit 33faf01

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

compiler/rustc_lint/src/early.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,14 @@ impl LintPass for EarlyLintPassObjects<'_> {
300300
}
301301
}
302302

303-
macro_rules! expand_early_lint_pass_impl_methods {
304-
([$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
305-
$(fn $name(&mut self, context: &EarlyContext<'_>, $($param: $arg),*) {
306-
for obj in self.lints.iter_mut() {
307-
obj.$name(context, $($param),*);
308-
}
309-
})*
310-
)
311-
}
312-
313303
macro_rules! early_lint_pass_impl {
314-
([], [$($methods:tt)*]) => (
304+
([], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
315305
impl EarlyLintPass for EarlyLintPassObjects<'_> {
316-
expand_early_lint_pass_impl_methods!([$($methods)*]);
306+
$(fn $name(&mut self, context: &EarlyContext<'_>, $($param: $arg),*) {
307+
for obj in self.lints.iter_mut() {
308+
obj.$name(context, $($param),*);
309+
}
310+
})*
317311
}
318312
)
319313
}

compiler/rustc_lint/src/late.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,14 @@ impl LintPass for LateLintPassObjects<'_, '_> {
313313
}
314314
}
315315

316-
macro_rules! expand_late_lint_pass_impl_methods {
317-
([$hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
318-
$(fn $name(&mut self, context: &LateContext<$hir>, $($param: $arg),*) {
319-
for obj in self.lints.iter_mut() {
320-
obj.$name(context, $($param),*);
321-
}
322-
})*
323-
)
324-
}
325-
326316
macro_rules! late_lint_pass_impl {
327-
([], [$hir:tt], $methods:tt) => {
317+
([], [$hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => {
328318
impl<$hir> LateLintPass<$hir> for LateLintPassObjects<'_, $hir> {
329-
expand_late_lint_pass_impl_methods!([$hir], $methods);
319+
$(fn $name(&mut self, context: &LateContext<$hir>, $($param: $arg),*) {
320+
for obj in self.lints.iter_mut() {
321+
obj.$name(context, $($param),*);
322+
}
323+
})*
330324
}
331325
};
332326
}

compiler/rustc_lint/src/passes.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,10 @@ macro_rules! late_lint_methods {
6666
// FIXME: eliminate the duplication with `Visitor`. But this also
6767
// contains a few lint-specific methods with no equivalent in `Visitor`.
6868

69-
macro_rules! expand_lint_pass_methods {
70-
($context:ty, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
71-
$(#[inline(always)] fn $name(&mut self, _: $context, $(_: $arg),*) {})*
72-
)
73-
}
74-
7569
macro_rules! declare_late_lint_pass {
76-
([], [$hir:tt], [$($methods:tt)*]) => (
70+
([], [$hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
7771
pub trait LateLintPass<$hir>: LintPass {
78-
expand_lint_pass_methods!(&LateContext<$hir>, [$($methods)*]);
72+
$(#[inline(always)] fn $name(&mut self, _: &LateContext<$hir>, $(_: $arg),*) {})*
7973
}
8074
)
8175
}
@@ -175,16 +169,10 @@ macro_rules! early_lint_methods {
175169
)
176170
}
177171

178-
macro_rules! expand_early_lint_pass_methods {
179-
($context:ty, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
180-
$(#[inline(always)] fn $name(&mut self, _: $context, $(_: $arg),*) {})*
181-
)
182-
}
183-
184172
macro_rules! declare_early_lint_pass {
185-
([], [$($methods:tt)*]) => (
173+
([], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
186174
pub trait EarlyLintPass: LintPass {
187-
expand_early_lint_pass_methods!(&EarlyContext<'_>, [$($methods)*]);
175+
$(#[inline(always)] fn $name(&mut self, _: &EarlyContext<'_>, $(_: $arg),*) {})*
188176
}
189177
)
190178
}

0 commit comments

Comments
 (0)