Skip to content

Commit ddad55f

Browse files
committed
Apply review comments + use shallow_lint_levels_on
1 parent 8a40884 commit ddad55f

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

compiler/rustc_lint/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
432432
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
433433
.into_iter()
434434
.filter(|pass| {
435-
let lints = LintPass::get_lints(pass);
435+
let lints = (**pass).get_lints();
436436
!lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint)))
437437
})
438438
.collect();

compiler/rustc_lint/src/levels.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use rustc_ast_pretty::pprust;
22
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
33
use rustc_errors::{Diag, LintDiagnostic, MultiSpan};
44
use rustc_feature::{Features, GateIssue};
5-
use rustc_hir::HirId;
65
use rustc_hir::intravisit::{self, Visitor};
6+
use rustc_hir::{CRATE_HIR_ID, HirId};
77
use rustc_index::IndexVec;
88
use rustc_middle::bug;
99
use rustc_middle::hir::nested_filter;
@@ -118,12 +118,22 @@ impl LintLevelSets {
118118
fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
119119
let store = unerased_lint_store(&tcx.sess);
120120

121+
let map = tcx.shallow_lint_levels_on(rustc_hir::CRATE_OWNER_ID);
122+
121123
let dont_need_to_run: FxIndexSet<LintId> = store
122124
.get_lints()
123125
.into_iter()
124126
.filter_map(|lint| {
125-
if !lint.eval_always && lint.default_level(tcx.sess.edition()) == Level::Allow {
126-
Some(LintId::of(lint))
127+
if !lint.eval_always {
128+
let lint_level = map.lint_level_id_at_node(tcx, LintId::of(lint), CRATE_HIR_ID);
129+
if matches!(lint_level, (Level::Allow, ..))
130+
|| (matches!(lint_level, (.., LintLevelSource::Default)))
131+
&& lint.default_level(tcx.sess.edition()) == Level::Allow
132+
{
133+
Some(LintId::of(lint))
134+
} else {
135+
None
136+
}
127137
} else {
128138
None
129139
}
@@ -372,7 +382,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
372382
) {
373383
let store = unerased_lint_store(self.tcx.sess);
374384
let Some(meta) = attribute.meta() else { return };
375-
// SAFETY: Lint attributes are always a metalist inside a
385+
// Lint attributes are always a metalist inside a
376386
// metalist (even with just one lint).
377387
let Some(meta_item_list) = meta.meta_item_list() else { return };
378388

@@ -387,7 +397,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
387397
.collect::<Vec<&str>>()
388398
.join("::");
389399
let Ok(lints) = store.find_lints(
390-
// SAFETY: Lint attributes can only have literals
400+
// Lint attributes can only have literals
391401
ident,
392402
) else {
393403
return;

compiler/rustc_lint_defs/src/lib.rs

-11
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,3 @@ macro_rules! declare_lint_pass {
968968
$crate::impl_lint_pass!($name => [$($lint),*]);
969969
};
970970
}
971-
972-
#[allow(rustc::lint_pass_impl_without_macro)]
973-
impl<P: LintPass + ?Sized> LintPass for Box<P> {
974-
fn name(&self) -> &'static str {
975-
(**self).name()
976-
}
977-
978-
fn get_lints(&self) -> LintVec {
979-
(**self).get_lints()
980-
}
981-
}

src/tools/clippy/clippy_lints/src/ctfe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_session::declare_lint_pass;
77
use rustc_span::Span;
88

99
/// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes).
10-
/// See rust-lang/rust#125116 for more info.
10+
/// As Clippy deactivates codegen, this lint ensures that CTFE (used in hard errors) is still ran.
1111
#[clippy::version = "1.82.0"]
1212
pub static CLIPPY_CTFE: &Lint = &Lint {
1313
name: &"clippy::CLIPPY_CTFE",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern crate clippy_utils;
6565
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
6666
mod utils;
6767

68-
pub mod ctfe; // Very important lint (rust#125116)
68+
pub mod ctfe; // Very important lint, do not remove (rust#125116)
6969
pub mod declared_lints;
7070
pub mod deprecated_lints;
7171

0 commit comments

Comments
 (0)