Skip to content

Commit aaf546c

Browse files
Auto merge of #142912 - Kobzol:early-lint-skip, r=<try>
[perf] Try to skip some early lints with `--cap-lints` Opening for perf. r? `@ghost`
2 parents 42245d3 + 6bc7c78 commit aaf546c

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

compiler/rustc_lint/src/early.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use rustc_ast::{self as ast, HasAttrs};
1010
use rustc_data_structures::stack::ensure_sufficient_stack;
1111
use rustc_feature::Features;
1212
use rustc_middle::ty::{RegisteredTools, TyCtxt};
13-
use rustc_session::Session;
1413
use rustc_session::lint::{BufferedEarlyLint, LintBuffer, LintPass};
14+
use rustc_session::{Session, lint};
1515
use rustc_span::{Ident, Span};
1616
use tracing::debug;
1717

18+
use crate::BuiltinCombinedEarlyLintPassMustRun;
1819
use crate::context::{EarlyContext, LintContext, LintStore};
1920
use crate::passes::{EarlyLintPass, EarlyLintPassObject};
2021

@@ -336,6 +337,18 @@ pub fn check_ast_node<'a>(
336337
let passes =
337338
if pre_expansion { &lint_store.pre_expansion_passes } else { &lint_store.early_passes };
338339
if passes.is_empty() {
340+
if let Some(tcx) = tcx {
341+
if sess.opts.lint_cap.is_some_and(|cap| cap == lint::Allow) {
342+
check_ast_node_inner(
343+
sess,
344+
Some(tcx),
345+
check_node,
346+
context,
347+
BuiltinCombinedEarlyLintPassMustRun::new(),
348+
);
349+
return;
350+
}
351+
}
339352
check_ast_node_inner(sess, tcx, check_node, context, builtin_lints);
340353
} else {
341354
let mut passes: Vec<_> = passes.iter().map(|mk_pass| (mk_pass)()).collect();

compiler/rustc_lint/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ early_lint_methods!(
186186
]
187187
);
188188

189+
early_lint_methods!(
190+
declare_combined_early_lint_pass,
191+
[
192+
pub BuiltinCombinedEarlyLintPassMustRun,
193+
[
194+
UnsafeCode: UnsafeCode,
195+
AnonymousParameters: AnonymousParameters,
196+
EllipsisInclusiveRangePatterns: EllipsisInclusiveRangePatterns::default(),
197+
Expr2024: Expr2024,
198+
]
199+
]
200+
);
201+
189202
late_lint_methods!(
190203
declare_combined_late_lint_pass,
191204
[

compiler/rustc_lint/src/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ macro_rules! declare_combined_early_lint_pass {
240240
#[allow(rustc::lint_pass_impl_without_macro)]
241241
impl $crate::LintPass for $name {
242242
fn name(&self) -> &'static str {
243-
panic!()
243+
stringify!($name)
244244
}
245245
fn get_lints(&self) -> LintVec {
246-
panic!()
246+
$name::get_lints()
247247
}
248248
}
249249
)

0 commit comments

Comments
 (0)