mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Apply review comments + use shallow_lint_levels_on
This commit is contained in:
parent
8a40884e1c
commit
ddad55f6c2
@ -432,7 +432,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
|||||||
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
|
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|pass| {
|
.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)))
|
!lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint)))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -2,8 +2,8 @@ use rustc_ast_pretty::pprust;
|
|||||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||||
use rustc_errors::{Diag, LintDiagnostic, MultiSpan};
|
use rustc_errors::{Diag, LintDiagnostic, MultiSpan};
|
||||||
use rustc_feature::{Features, GateIssue};
|
use rustc_feature::{Features, GateIssue};
|
||||||
use rustc_hir::HirId;
|
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
|
use rustc_hir::{CRATE_HIR_ID, HirId};
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
@ -118,15 +118,25 @@ impl LintLevelSets {
|
|||||||
fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
|
fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
|
||||||
let store = unerased_lint_store(&tcx.sess);
|
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
|
let dont_need_to_run: FxIndexSet<LintId> = store
|
||||||
.get_lints()
|
.get_lints()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|lint| {
|
.filter_map(|lint| {
|
||||||
if !lint.eval_always && lint.default_level(tcx.sess.edition()) == Level::Allow {
|
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))
|
Some(LintId::of(lint))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -372,7 +382,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
|
|||||||
) {
|
) {
|
||||||
let store = unerased_lint_store(self.tcx.sess);
|
let store = unerased_lint_store(self.tcx.sess);
|
||||||
let Some(meta) = attribute.meta() else { return };
|
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).
|
// metalist (even with just one lint).
|
||||||
let Some(meta_item_list) = meta.meta_item_list() else { return };
|
let Some(meta_item_list) = meta.meta_item_list() else { return };
|
||||||
|
|
||||||
@ -387,7 +397,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
|
|||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("::");
|
.join("::");
|
||||||
let Ok(lints) = store.find_lints(
|
let Ok(lints) = store.find_lints(
|
||||||
// SAFETY: Lint attributes can only have literals
|
// Lint attributes can only have literals
|
||||||
ident,
|
ident,
|
||||||
) else {
|
) else {
|
||||||
return;
|
return;
|
||||||
|
@ -968,14 +968,3 @@ macro_rules! declare_lint_pass {
|
|||||||
$crate::impl_lint_pass!($name => [$($lint),*]);
|
$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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -7,7 +7,7 @@ use rustc_session::declare_lint_pass;
|
|||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
/// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes).
|
/// 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"]
|
#[clippy::version = "1.82.0"]
|
||||||
pub static CLIPPY_CTFE: &Lint = &Lint {
|
pub static CLIPPY_CTFE: &Lint = &Lint {
|
||||||
name: &"clippy::CLIPPY_CTFE",
|
name: &"clippy::CLIPPY_CTFE",
|
||||||
|
@ -65,7 +65,7 @@ extern crate clippy_utils;
|
|||||||
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
|
#[cfg_attr(feature = "internal", allow(clippy::missing_clippy_version_attribute))]
|
||||||
mod utils;
|
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 declared_lints;
|
||||||
pub mod deprecated_lints;
|
pub mod deprecated_lints;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user