Skip to content

Commit eb31c51

Browse files
committed
Auto merge of #160187 - cjgillot:lint-should-be-skipped, r=<try>
Hide skippable_lints.
2 parents 1a833e1 + a7a6907 commit eb31c51

9 files changed

Lines changed: 28 additions & 27 deletions

File tree

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ fn resolve_block<'tcx>(
146146
let edition = blk.span.edition();
147147
let terminating = edition.at_least_rust_2024();
148148
if !terminating
149-
&& !visitor
150-
.tcx
151-
.skippable_lints(())
152-
.contains(&lint::LintId::of(lint::builtin::TAIL_EXPR_DROP_ORDER))
149+
&& !visitor.tcx.lint_should_be_skipped(lint::builtin::TAIL_EXPR_DROP_ORDER)
153150
{
154151
// If this temporary scope will be changing once the codebase adopts Rust 2024,
155152
// and we are linting about possible semantic changes that would result,

compiler/rustc_lint/src/if_let_rescope.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::significant_drop_order::{
1111
extract_component_with_significant_dtor, ty_dtor_span,
1212
};
1313
use rustc_middle::ty::{self, Ty, TyCtxt};
14-
use rustc_session::lint::{LintId, fcw};
14+
use rustc_session::lint::fcw;
1515
use rustc_session::{declare_lint, impl_lint_pass};
1616
use rustc_span::{DUMMY_SP, Span};
1717
use smallvec::SmallVec;
@@ -268,8 +268,7 @@ impl_lint_pass!(
268268

269269
impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
270270
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
271-
if expr.span.edition().at_least_rust_2024()
272-
|| cx.tcx.skippable_lints(()).contains(&LintId::of(IF_LET_RESCOPE))
271+
if expr.span.edition().at_least_rust_2024() || cx.tcx.lint_should_be_skipped(IF_LET_RESCOPE)
273272
{
274273
return;
275274
}

compiler/rustc_lint/src/late.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,16 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
348348
only_module: true,
349349
};
350350

351-
let skippable_lints = tcx.skippable_lints(());
352-
353351
// Note: `passes` is often empty. In that case, it's faster to run
354352
// `builtin_lints` directly rather than bundling it up into the
355353
// `RuntimeCombinedLateLintPass`.
356354
let mut passes: Vec<_> = unerased_lint_store(tcx.sess)
357355
.late_lint_mod_passes
358356
.iter()
359357
.map(|mk_pass| mk_pass(tcx))
360-
.filter(|pass| is_lint_pass_required(skippable_lints, &pass.get_lints()))
358+
.filter(|pass| is_lint_pass_required(tcx, &pass.get_lints()))
361359
.collect();
362-
let builtin_lints_must_run = is_lint_pass_required(skippable_lints, &builtin_lints.get_lints());
360+
let builtin_lints_must_run = is_lint_pass_required(tcx, &builtin_lints.get_lints());
363361
if passes.is_empty() {
364362
if builtin_lints_must_run {
365363
late_lint_mod_inner(tcx, mod_id, context, builtin_lints);
@@ -398,14 +396,12 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
398396
}
399397

400398
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
401-
let skippable_lints = tcx.skippable_lints(());
402-
403399
// Note: `passes` is often empty after filtering.
404400
let passes: Vec<_> = unerased_lint_store(tcx.sess)
405401
.late_lint_passes
406402
.iter()
407403
.map(|mk_pass| mk_pass(tcx))
408-
.filter(|pass| is_lint_pass_required(skippable_lints, &pass.get_lints()))
404+
.filter(|pass| is_lint_pass_required(tcx, &pass.get_lints()))
409405
.collect();
410406
if passes.is_empty() {
411407
return;

compiler/rustc_lint/src/levels.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ fn skippable_lints(tcx: TyCtxt<'_>, (): ()) -> UnordSet<LintId> {
121121
let mut skippable: FxHashSet<LintId> = store
122122
.get_lints()
123123
.into_iter()
124-
.filter(|lint| {
125-
// Lints that show up in future-compat reports must always be run.
126-
let has_future_breakage =
127-
lint.future_incompatible.is_some_and(|fut| fut.report_in_deps);
128-
!has_future_breakage && !lint.eval_always
129-
})
130124
.filter(|lint| {
131125
let level_spec =
132126
root_map.lint_level_spec_at_node(tcx, LintId::of(lint), hir::CRATE_HIR_ID);

compiler/rustc_lint/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ use ptr_nulls::*;
120120
use redundant_semicolon::*;
121121
use reference_casting::*;
122122
use runtime_symbols::*;
123-
use rustc_data_structures::unord::UnordSet;
124123
use rustc_hir::def_id::LocalModId;
125124
use rustc_middle::query::Providers;
126125
use rustc_middle::ty::TyCtxt;
@@ -754,15 +753,15 @@ fn register_internals(store: &mut LintStore) {
754753
///
755754
/// Note: this is a conservative estimate intended for optimization purposes. It might return
756755
/// `true` for a pass that need not run, but it will never return `false` for a pass that must run.
757-
pub fn is_lint_pass_required(skippable: &UnordSet<LintId>, lints: &LintVec) -> bool {
756+
pub fn is_lint_pass_required(tcx: TyCtxt<'_>, lints: &LintVec) -> bool {
758757
// A pass without any lints? Clippy sometimes does this, to collect things while traversing.
759758
// Such a pass must always run.
760759
if lints.is_empty() {
761760
return true;
762761
}
763762

764763
// Otherwise, the pass must run unless all lints within are skippable.
765-
!lints.iter().all(|lint| skippable.contains(&LintId::of(lint)))
764+
!lints.iter().all(|lint| tcx.lint_should_be_skipped(lint))
766765
}
767766

768767
#[cfg(test)]

compiler/rustc_middle/src/lint.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,22 @@ impl ShallowLintLevelMap {
244244
}
245245

246246
impl TyCtxt<'_> {
247+
/// Return whether the code to produce this lint can be skipped.
248+
pub fn lint_should_be_skipped(self, lint: &'static Lint) -> bool {
249+
if lint.eval_always {
250+
return false;
251+
}
252+
253+
// Lints that show up in future-compat reports must always be run.
254+
if let Some(fut) = lint.future_incompatible
255+
&& fut.report_in_deps
256+
{
257+
return false;
258+
}
259+
260+
self.skippable_lints(()).contains(&LintId::of(lint))
261+
}
262+
247263
/// Fetch and return the user-visible lint level spec for the given lint at the given HirId.
248264
pub fn lint_level_spec_at_node(self, lint: &'static Lint, id: HirId) -> StableLevelSpec {
249265
self.shallow_lint_levels_on(id.owner).lint_level_spec_at_node(self, LintId::of(lint), id)

compiler/rustc_middle/src/queries.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ rustc_queries! {
547547
desc { "computing `#[expect]`ed lints in this crate" }
548548
}
549549

550+
/// Gathers lints that are alloed in the whole crate and do not need to be computed.
551+
/// Do not use this query directly, use `tcx.lint_should_be_skipped(lint)` instead.
550552
query skippable_lints(_: ()) -> &'tcx UnordSet<LintId> {
551553
arena_cache
552554
// This depends on the lint store, which includes internal lints when the

compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
186186
// A synthetic coroutine has no HIR body and it is enough to just analyse the original body
187187
return;
188188
}
189-
if body.span.edition().at_least_rust_2024()
190-
|| tcx.skippable_lints(()).contains(&lint::LintId::of(TAIL_EXPR_DROP_ORDER))
189+
if body.span.edition().at_least_rust_2024() || tcx.lint_should_be_skipped(TAIL_EXPR_DROP_ORDER)
191190
{
192191
return;
193192
}

src/tools/clippy/clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
469469
}
470470

471471
store.register_late_lint_pass(Box::new(move |tcx: TyCtxt<'_>| {
472-
let skippable_lints = tcx.skippable_lints(());
473-
let is_active = |lints: &rustc_lint::LintVec| is_lint_pass_required(skippable_lints, lints);
472+
let is_active = |lints: &rustc_lint::LintVec| is_lint_pass_required(tcx, lints);
474473
Box::new(CombinedLateLintPass::new(
475474
tcx,
476475
conf,

0 commit comments

Comments
 (0)