1
Fork 0

Auto merge of #104863 - nnethercote:reduce-lint-macros, r=cjgillot

Reduce macro usage for lints

r? `@cjgillot`
This commit is contained in:
bors 2022-12-02 15:31:15 +00:00
commit e960b5e774
24 changed files with 254 additions and 550 deletions

View file

@ -1,7 +1,6 @@
use crate::context::{EarlyContext, LateContext};
use rustc_ast as ast;
use rustc_data_structures::sync;
use rustc_hir as hir;
use rustc_session::lint::builtin::HardwiredLints;
use rustc_session::lint::LintPass;
@ -66,16 +65,10 @@ macro_rules! late_lint_methods {
// FIXME: eliminate the duplication with `Visitor`. But this also
// contains a few lint-specific methods with no equivalent in `Visitor`.
macro_rules! expand_lint_pass_methods {
($context:ty, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(#[inline(always)] fn $name(&mut self, _: $context, $(_: $arg),*) {})*
)
}
macro_rules! declare_late_lint_pass {
([], [$hir:tt], [$($methods:tt)*]) => (
([], [$hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
pub trait LateLintPass<$hir>: LintPass {
expand_lint_pass_methods!(&LateContext<$hir>, [$($methods)*]);
$(#[inline(always)] fn $name(&mut self, _: &LateContext<$hir>, $(_: $arg),*) {})*
}
)
}
@ -175,16 +168,10 @@ macro_rules! early_lint_methods {
)
}
macro_rules! expand_early_lint_pass_methods {
($context:ty, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(#[inline(always)] fn $name(&mut self, _: $context, $(_: $arg),*) {})*
)
}
macro_rules! declare_early_lint_pass {
([], [$($methods:tt)*]) => (
([], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
pub trait EarlyLintPass: LintPass {
expand_early_lint_pass_methods!(&EarlyContext<'_>, [$($methods)*]);
$(#[inline(always)] fn $name(&mut self, _: &EarlyContext<'_>, $(_: $arg),*) {})*
}
)
}
@ -243,5 +230,5 @@ macro_rules! declare_combined_early_lint_pass {
}
/// A lint pass boxed up as a trait object.
pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + 'static>;
pub type LateLintPassObject<'tcx> = Box<dyn LateLintPass<'tcx> + sync::Send + 'tcx>;
pub type EarlyLintPassObject = Box<dyn EarlyLintPass + 'static>;
pub type LateLintPassObject<'tcx> = Box<dyn LateLintPass<'tcx> + 'tcx>;