From ddad55f6c214357f48134d00050c6dbfcf1d9215 Mon Sep 17 00:00:00 2001 From: blyxyas Date: Tue, 15 Oct 2024 22:15:07 +0200 Subject: [PATCH] Apply review comments + use `shallow_lint_levels_on` --- compiler/rustc_lint/src/late.rs | 2 +- compiler/rustc_lint/src/levels.rs | 20 +++++++++++++++----- compiler/rustc_lint_defs/src/lib.rs | 11 ----------- src/tools/clippy/clippy_lints/src/ctfe.rs | 2 +- src/tools/clippy/clippy_lints/src/lib.rs | 2 +- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index ea7a44dd123..9b1877599ba 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -432,7 +432,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) { let mut filtered_passes: Vec>> = passes .into_iter() .filter(|pass| { - let lints = LintPass::get_lints(pass); + let lints = (**pass).get_lints(); !lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint))) }) .collect(); diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 64e1cddf248..2c12899fad0 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -2,8 +2,8 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_errors::{Diag, LintDiagnostic, MultiSpan}; use rustc_feature::{Features, GateIssue}; -use rustc_hir::HirId; use rustc_hir::intravisit::{self, Visitor}; +use rustc_hir::{CRATE_HIR_ID, HirId}; use rustc_index::IndexVec; use rustc_middle::bug; use rustc_middle::hir::nested_filter; @@ -118,12 +118,22 @@ fn raw_lint_id_level( fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet { let store = unerased_lint_store(&tcx.sess); + let map = tcx.shallow_lint_levels_on(rustc_hir::CRATE_OWNER_ID); + let dont_need_to_run: FxIndexSet = store .get_lints() .into_iter() .filter_map(|lint| { - if !lint.eval_always && lint.default_level(tcx.sess.edition()) == Level::Allow { - Some(LintId::of(lint)) + if !lint.eval_always { + let lint_level = map.lint_level_id_at_node(tcx, LintId::of(lint), CRATE_HIR_ID); + if matches!(lint_level, (Level::Allow, ..)) + || (matches!(lint_level, (.., LintLevelSource::Default))) + && lint.default_level(tcx.sess.edition()) == Level::Allow + { + Some(LintId::of(lint)) + } else { + None + } } else { None } @@ -372,7 +382,7 @@ fn visit_attribute(&mut self, attribute: &'tcx ast::Attribute) { ) { let store = unerased_lint_store(self.tcx.sess); let Some(meta) = attribute.meta() else { return }; - // SAFETY: Lint attributes are always a metalist inside a + // Lint attributes are always a metalist inside a // metalist (even with just one lint). let Some(meta_item_list) = meta.meta_item_list() else { return }; @@ -387,7 +397,7 @@ fn visit_attribute(&mut self, attribute: &'tcx ast::Attribute) { .collect::>() .join("::"); let Ok(lints) = store.find_lints( - // SAFETY: Lint attributes can only have literals + // Lint attributes can only have literals ident, ) else { return; diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 320668a5dbf..418caa699e2 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -968,14 +968,3 @@ macro_rules! declare_lint_pass { $crate::impl_lint_pass!($name => [$($lint),*]); }; } - -#[allow(rustc::lint_pass_impl_without_macro)] -impl LintPass for Box

{ - fn name(&self) -> &'static str { - (**self).name() - } - - fn get_lints(&self) -> LintVec { - (**self).get_lints() - } -} diff --git a/src/tools/clippy/clippy_lints/src/ctfe.rs b/src/tools/clippy/clippy_lints/src/ctfe.rs index ddb4eb82165..93d0ad789be 100644 --- a/src/tools/clippy/clippy_lints/src/ctfe.rs +++ b/src/tools/clippy/clippy_lints/src/ctfe.rs @@ -7,7 +7,7 @@ use rustc_span::Span; /// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes). -/// See rust-lang/rust#125116 for more info. +/// As Clippy deactivates codegen, this lint ensures that CTFE (used in hard errors) is still ran. #[clippy::version = "1.82.0"] pub static CLIPPY_CTFE: &Lint = &Lint { name: &"clippy::CLIPPY_CTFE", diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 88a227f5b6d..14110539709 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -65,7 +65,7 @@ #[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))] mod utils; -pub mod ctfe; // Very important lint (rust#125116) +pub mod ctfe; // Very important lint, do not remove (rust#125116) pub mod declared_lints; pub mod deprecated_lints;