Skip to content

Commit

Permalink
Apply review comments + use shallow_lint_levels_on
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Oct 19, 2024
1 parent 8a40884 commit ddad55f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = 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();
Expand Down
20 changes: 15 additions & 5 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use rustc_ast_pretty::pprust;
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;
Expand Down Expand Up @@ -118,12 +118,22 @@ impl LintLevelSets {
fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
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<LintId> = 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
}
Expand Down Expand Up @@ -372,7 +382,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
) {
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 };

Expand All @@ -387,7 +397,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
.collect::<Vec<&str>>()
.join("::");
let Ok(lints) = store.find_lints(
// SAFETY: Lint attributes can only have literals
// Lint attributes can only have literals
ident,
) else {
return;
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,14 +968,3 @@ macro_rules! declare_lint_pass {
$crate::impl_lint_pass!($name => [$($lint),*]);
};
}

#[allow(rustc::lint_pass_impl_without_macro)]
impl<P: LintPass + ?Sized> LintPass for Box<P> {
fn name(&self) -> &'static str {
(**self).name()
}

fn get_lints(&self) -> LintVec {
(**self).get_lints()
}
}
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/ctfe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_session::declare_lint_pass;
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",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern crate clippy_utils;
#[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;

Expand Down

0 comments on commit ddad55f

Please sign in to comment.