Skip to content

Commit 6b1716e

Browse files
Use runtime late lint pass for builtin late lint pass
1 parent f24e766 commit 6b1716e

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

compiler/rustc_lint/src/late.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
307307
// `check_foo` method in `$methods` within this pass simply calls `check_foo`
308308
// once per `$pass`. Compare with `declare_combined_late_lint_pass`, which is
309309
// similar, but combines lint passes at compile time.
310-
struct RuntimeCombinedLateLintPass<'tcx> {
311-
passes: Vec<LateLintPassObject<'tcx>>,
310+
pub struct RuntimeCombinedLateLintPass<'tcx> {
311+
pub passes: Vec<LateLintPassObject<'tcx>>,
312312
}
313313

314314
#[allow(rustc::lint_pass_impl_without_macro)]

compiler/rustc_lint/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub use context::{
129129
CheckLintNameResult, EarlyContext, FindLintError, LateContext, LintContext, LintStore,
130130
};
131131
pub use early::{EarlyCheckNode, check_ast_node};
132-
pub use late::{check_crate, late_lint_mod, unerased_lint_store};
132+
pub use late::{RuntimeCombinedLateLintPass, check_crate, late_lint_mod, unerased_lint_store};
133133
pub use passes::{EarlyLintPass, LateLintPass};
134134
pub use rustc_session::lint::Level::{self, *};
135135
pub use rustc_session::lint::{
@@ -146,7 +146,7 @@ pub fn provide(providers: &mut Providers) {
146146
}
147147

148148
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
149-
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
149+
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new(tcx));
150150
}
151151

152152
early_lint_methods!(

compiler/rustc_lint/src/passes.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,11 @@ late_lint_methods!(declare_late_lint_pass, []);
7272

7373
impl LateLintPass<'_> for HardwiredLints {}
7474

75-
#[macro_export]
76-
macro_rules! expand_combined_late_lint_pass_method {
77-
([$($pass:ident),*], $self: ident, $name: ident, $params:tt) => ({
78-
$($self.$pass.$name $params;)*
79-
})
80-
}
81-
8275
#[macro_export]
8376
macro_rules! expand_combined_late_lint_pass_methods {
8477
($passes:tt, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
8578
$(fn $name(&mut self, context: &$crate::LateContext<'tcx>, $($param: $arg),*) {
86-
$crate::expand_combined_late_lint_pass_method!($passes, self, $name, (context, $($param),*));
79+
self.inner.$name(context$(, $param)*);
8780
})*
8881
)
8982
}
@@ -97,15 +90,15 @@ macro_rules! expand_combined_late_lint_pass_methods {
9790
macro_rules! declare_combined_late_lint_pass {
9891
([$v:vis $name:ident, [$($pass:ident: $constructor:expr,)*]], $methods:tt) => (
9992
#[allow(non_snake_case)]
100-
$v struct $name {
101-
$($pass: $pass,)*
93+
$v struct $name<'tcx> {
94+
inner: RuntimeCombinedLateLintPass<'tcx>,
10295
}
10396

104-
impl $name {
105-
$v fn new() -> Self {
106-
Self {
107-
$($pass: $constructor,)*
108-
}
97+
impl<'tcx> $name<'tcx> {
98+
$v fn new(_tcx: TyCtxt<'tcx>) -> Self {
99+
let mut passes = vec![];
100+
$(passes.push(Box::new($constructor) as Box<dyn LateLintPass<'tcx>>);)*
101+
$name { inner: RuntimeCombinedLateLintPass { passes } }
109102
}
110103

111104
$v fn get_lints() -> $crate::LintVec {
@@ -115,12 +108,12 @@ macro_rules! declare_combined_late_lint_pass {
115108
}
116109
}
117110

118-
impl<'tcx> $crate::LateLintPass<'tcx> for $name {
111+
impl<'tcx> $crate::LateLintPass<'tcx> for $name<'tcx> {
119112
$crate::expand_combined_late_lint_pass_methods!([$($pass),*], $methods);
120113
}
121114

122115
#[allow(rustc::lint_pass_impl_without_macro)]
123-
impl $crate::LintPass for $name {
116+
impl $crate::LintPass for $name<'_> {
124117
fn name(&self) -> &'static str {
125118
panic!()
126119
}

0 commit comments

Comments
 (0)