Skip to content

Commit 0d5b1b6

Browse files
committed
Auto merge of #139597 - Kobzol:lint-skip, r=<try>
Do not run per-module lints if they can be all skipped We run ~70 late lints for all dependencies even if they use `--cap-lints=allow`, which seems wasteful. It looks like these lints are super fast, but still. r? `@ghost`
2 parents 48f89e7 + 3c4fb44 commit 0d5b1b6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

compiler/rustc_lint/src/late.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,14 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
356356
let store = unerased_lint_store(tcx.sess);
357357

358358
if store.late_module_passes.is_empty() {
359-
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
359+
// If all builtin lints can be skipped, there is no point in running `late_lint_mod_inner`
360+
// at all. This happens often for dependencies built with `--cap-lints=allow`.
361+
let dont_need_to_run = tcx.lints_that_dont_need_to_run(());
362+
let can_skip_lints =
363+
builtin_lints.get_lints().iter().all(|l| dont_need_to_run.contains(&LintId::of(l)));
364+
if !can_skip_lints {
365+
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
366+
}
360367
} else {
361368
let builtin_lints = Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>;
362369
let mut binding = store

compiler/rustc_lint/src/passes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ macro_rules! expand_combined_late_lint_pass_methods {
9292
/// Combines multiple lints passes into a single lint pass, at compile time,
9393
/// for maximum speed. Each `check_foo` method in `$methods` within this pass
9494
/// simply calls `check_foo` once per `$pass`. Compare with
95-
/// `LateLintPassObjects`, which is similar, but combines lint passes at
95+
/// `RuntimeCombinedLateLintPass`, which is similar, but combines lint passes at
9696
/// runtime.
9797
#[macro_export]
9898
macro_rules! declare_combined_late_lint_pass {
@@ -123,10 +123,10 @@ macro_rules! declare_combined_late_lint_pass {
123123
#[allow(rustc::lint_pass_impl_without_macro)]
124124
impl $crate::LintPass for $name {
125125
fn name(&self) -> &'static str {
126-
panic!()
126+
stringify!($name)
127127
}
128128
fn get_lints(&self) -> LintVec {
129-
panic!()
129+
$name::get_lints()
130130
}
131131
}
132132
)

0 commit comments

Comments
 (0)