Remove module passes filtering
This commit is contained in:
parent
71b4d108c7
commit
637d5cc56f
16 changed files with 109 additions and 212 deletions
|
@ -972,7 +972,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
|
||||||
tcx.ensure().check_mod_privacy(module);
|
tcx.ensure().check_mod_privacy(module);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} // { sess.time("mir_checking", || { tcx.hir().mir_for }) }
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// This check has to be run after all lints are done processing. We don't
|
// This check has to be run after all lints are done processing. We don't
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
//! If you define a new `LateLintPass`, you will also need to add it to the
|
//! If you define a new `LateLintPass`, you will also need to add it to the
|
||||||
//! `late_lint_methods!` invocation in `lib.rs`.
|
//! `late_lint_methods!` invocation in `lib.rs`.
|
||||||
|
|
||||||
use std::default::Default;
|
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use ast::token::TokenKind;
|
use ast::token::TokenKind;
|
||||||
|
@ -74,11 +73,6 @@ use crate::{
|
||||||
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
|
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
|
||||||
fluent_generated as fluent,
|
fluent_generated as fluent,
|
||||||
};
|
};
|
||||||
// use std::fmt::Write;
|
|
||||||
|
|
||||||
// hardwired lints from rustc_lint_defs
|
|
||||||
// pub use rustc_session::lint::builtin::*;
|
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
/// The `while_true` lint detects `while true { }`.
|
/// The `while_true` lint detects `while true { }`.
|
||||||
///
|
///
|
||||||
|
@ -247,7 +241,7 @@ declare_lint! {
|
||||||
UNSAFE_CODE,
|
UNSAFE_CODE,
|
||||||
Allow,
|
Allow,
|
||||||
"usage of `unsafe` code and other potentially unsound constructs",
|
"usage of `unsafe` code and other potentially unsound constructs",
|
||||||
[loadbearing: true]
|
@eval_always = true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]);
|
declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]);
|
||||||
|
|
|
@ -430,7 +430,7 @@ declare_tool_lint! {
|
||||||
Deny,
|
Deny,
|
||||||
"prevent creation of diagnostics which cannot be translated",
|
"prevent creation of diagnostics which cannot be translated",
|
||||||
report_in_external_macro: true,
|
report_in_external_macro: true,
|
||||||
[loadbearing: true]
|
eval_always: true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_tool_lint! {
|
declare_tool_lint! {
|
||||||
|
@ -444,7 +444,7 @@ declare_tool_lint! {
|
||||||
Deny,
|
Deny,
|
||||||
"prevent diagnostic creation outside of `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls",
|
"prevent diagnostic creation outside of `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls",
|
||||||
report_in_external_macro: true,
|
report_in_external_macro: true,
|
||||||
[loadbearing: true]
|
eval_always: true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL]);
|
declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL]);
|
||||||
|
|
|
@ -24,7 +24,9 @@ use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
||||||
use rustc_hir::{HirId, intravisit as hir_visit};
|
use rustc_hir::{HirId, intravisit as hir_visit};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_session::{Session, lint::{LintPass, builtin::HardwiredLints}};
|
use rustc_session::Session;
|
||||||
|
use rustc_session::lint::LintPass;
|
||||||
|
use rustc_session::lint::builtin::HardwiredLints;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
@ -368,28 +370,15 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
|
||||||
if store.late_module_passes.is_empty() {
|
if store.late_module_passes.is_empty() {
|
||||||
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
|
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
|
||||||
} else {
|
} else {
|
||||||
let passes: Vec<_> =
|
let builtin_lints = Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>;
|
||||||
store.late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
let mut binding = store
|
||||||
// Filter unused lints
|
.late_module_passes
|
||||||
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
|
.iter()
|
||||||
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
|
.map(|mk_pass| (mk_pass)(tcx))
|
||||||
.into_iter()
|
.chain(std::iter::once(builtin_lints))
|
||||||
.filter(|pass| {
|
.collect::<Vec<_>>();
|
||||||
let lints = LintPass::get_lints(pass);
|
|
||||||
if lints.is_empty() {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
lints
|
|
||||||
.iter()
|
|
||||||
.any(|lint| !lints_that_dont_need_to_run.contains(&LintId::of(lint)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
filtered_passes.push(Box::new(builtin_lints));
|
let pass = RuntimeCombinedLateLintPass { passes: binding.as_mut_slice() };
|
||||||
filtered_passes.push(Box::new(HardwiredLints));
|
|
||||||
|
|
||||||
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
|
|
||||||
late_lint_mod_inner(tcx, module_def_id, context, pass);
|
late_lint_mod_inner(tcx, module_def_id, context, pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,7 +429,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||||
|
|
||||||
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
|
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
|
||||||
|
|
||||||
// dbg!(&lints_that_dont_need_to_run);
|
|
||||||
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| {
|
||||||
|
@ -450,17 +438,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
filtered_passes.push(Box::new(HardwiredLints));
|
filtered_passes.push(Box::new(HardwiredLints));
|
||||||
|
|
||||||
// let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
|
|
||||||
// .into_iter()
|
|
||||||
// .filter(|pass| {
|
|
||||||
// let lints = LintPass::get_lints(pass);
|
|
||||||
// lints.iter()
|
|
||||||
// .any(|lint|
|
|
||||||
// !lints_that_dont_need_to_run.contains(&LintId::of(lint)))
|
|
||||||
// }).collect();
|
|
||||||
//
|
|
||||||
|
|
||||||
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
|
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
|
||||||
late_lint_crate_inner(tcx, context, pass);
|
late_lint_crate_inner(tcx, context, pass);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ use crate::errors::{
|
||||||
OverruledAttributeSub, RequestedLevel, UnknownToolInScopedLint, UnsupportedGroup,
|
OverruledAttributeSub, RequestedLevel, UnknownToolInScopedLint, UnsupportedGroup,
|
||||||
};
|
};
|
||||||
use crate::fluent_generated as fluent;
|
use crate::fluent_generated as fluent;
|
||||||
use crate::late::{unerased_lint_store /*name_without_tool*/};
|
use crate::late::unerased_lint_store;
|
||||||
use crate::lints::{
|
use crate::lints::{
|
||||||
DeprecatedLintName, DeprecatedLintNameFromCommandLine, IgnoredUnlessCrateSpecified,
|
DeprecatedLintName, DeprecatedLintNameFromCommandLine, IgnoredUnlessCrateSpecified,
|
||||||
OverruledAttributeLint, RemovedLint, RemovedLintFromCommandLine, RenamedLint,
|
OverruledAttributeLint, RemovedLint, RemovedLintFromCommandLine, RenamedLint,
|
||||||
|
@ -122,7 +122,7 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
|
||||||
.get_lints()
|
.get_lints()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|lint| {
|
.filter_map(|lint| {
|
||||||
if !lint.loadbearing && lint.default_level(tcx.sess.edition()) == Level::Allow {
|
if !lint.eval_always && lint.default_level(tcx.sess.edition()) == Level::Allow {
|
||||||
Some(LintId::of(lint))
|
Some(LintId::of(lint))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -134,21 +134,6 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
|
||||||
visitor.process_opts();
|
visitor.process_opts();
|
||||||
tcx.hir().walk_attributes(&mut visitor);
|
tcx.hir().walk_attributes(&mut visitor);
|
||||||
|
|
||||||
// let lint_groups = store.get_lint_groups();
|
|
||||||
// for group in lint_groups {
|
|
||||||
// let binding = group.0.to_lowercase();
|
|
||||||
// let group_name = name_without_tool(&binding).to_string();
|
|
||||||
// if visitor.lints_that_actually_run.contains(&group_name) {
|
|
||||||
// for lint in group.1 {
|
|
||||||
// visitor.lints_that_actually_run.insert(name_without_tool(&lint.to_string()).to_string());
|
|
||||||
// }
|
|
||||||
// } else if visitor.lints_allowed.contains(&group_name) {
|
|
||||||
// for lint in &group.1 {
|
|
||||||
// visitor.lints_allowed.insert(name_without_tool(&lint.to_string()).to_string());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
visitor.dont_need_to_run
|
visitor.dont_need_to_run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,83 +357,44 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
|
||||||
self.tcx.hir()
|
self.tcx.hir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// FIXME(blyxyas): In a future revision, we should also graph #![allow]s,
|
||||||
|
/// but that is handled with more care
|
||||||
fn visit_attribute(&mut self, attribute: &'tcx ast::Attribute) {
|
fn visit_attribute(&mut self, attribute: &'tcx ast::Attribute) {
|
||||||
match Level::from_attr(attribute) {
|
if matches!(
|
||||||
|
Level::from_attr(attribute),
|
||||||
Some(
|
Some(
|
||||||
Level::Warn
|
Level::Warn
|
||||||
| Level::Deny
|
| Level::Deny
|
||||||
| Level::Forbid
|
| Level::Forbid
|
||||||
| Level::Expect(..)
|
| Level::Expect(..)
|
||||||
| Level::ForceWarn(..),
|
| Level::ForceWarn(..),
|
||||||
) => {
|
)
|
||||||
let store = unerased_lint_store(self.tcx.sess);
|
) {
|
||||||
let Some(meta) = attribute.meta() else { return };
|
let store = unerased_lint_store(self.tcx.sess);
|
||||||
// SAFETY: Lint attributes are always a metalist inside a
|
let Some(meta) = attribute.meta() else { return };
|
||||||
// metalist (even with just one lint).
|
// SAFETY: Lint attributes are always a metalist inside a
|
||||||
let Some(meta_item_list) = meta.meta_item_list() else { return };
|
// metalist (even with just one lint).
|
||||||
|
let Some(meta_item_list) = meta.meta_item_list() else { return };
|
||||||
|
|
||||||
for meta_list in meta_item_list {
|
for meta_list in meta_item_list {
|
||||||
// Convert Path to String
|
// Convert Path to String
|
||||||
let Some(meta_item) = meta_list.meta_item() else { return };
|
let Some(meta_item) = meta_list.meta_item() else { return };
|
||||||
let ident: &str = &meta_item
|
let ident: &str = &meta_item
|
||||||
.path
|
.path
|
||||||
.segments
|
.segments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|segment| segment.ident.as_str())
|
.map(|segment| segment.ident.as_str())
|
||||||
.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
|
// SAFETY: Lint attributes can only have literals
|
||||||
ident,
|
ident,
|
||||||
) else {
|
) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
for lint in lints {
|
for lint in lints {
|
||||||
self.dont_need_to_run.swap_remove(&lint);
|
self.dont_need_to_run.swap_remove(&lint);
|
||||||
}
|
|
||||||
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
|
|
||||||
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
|
|
||||||
// if meta_item.path.segments.len() == 1 {
|
|
||||||
// let Ok(lints) = store.find_lints(
|
|
||||||
// // SAFETY: Lint attributes can only have literals
|
|
||||||
// meta_list.ident().unwrap().name.as_str(),
|
|
||||||
// ) else {
|
|
||||||
// return;
|
|
||||||
// };
|
|
||||||
// for lint in lints {
|
|
||||||
// dbg!("LINT REMOVED", &lint);
|
|
||||||
// self.dont_need_to_run.swap_remove(&lint);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// let Ok(lints) = store.find_lints(
|
|
||||||
// // SAFETY: Lint attributes can only have literals
|
|
||||||
// meta_item.path.segments[1].ident.name.as_str(),
|
|
||||||
// ) else {
|
|
||||||
// return;
|
|
||||||
// };
|
|
||||||
// for lint in lints {
|
|
||||||
// dbg!("LINT REMOVED", &lint);
|
|
||||||
// self.dont_need_to_run.swap_remove(&lint);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
// We handle #![allow]s differently, as these remove checking rather than adding.
|
|
||||||
} // Some(Level::Allow) if ast::AttrStyle::Inner == attribute.style => {
|
|
||||||
// for meta_list in meta.meta_item_list().unwrap() {
|
|
||||||
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
|
|
||||||
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
|
|
||||||
// if meta_item.path.segments.len() == 1 {
|
|
||||||
// self.lints_allowed
|
|
||||||
// .insert(meta_list.name_or_empty().as_str().to_string());
|
|
||||||
// } else {
|
|
||||||
// self.lints_allowed
|
|
||||||
// .insert(meta_item.path.segments[1].ident.name.as_str().to_string());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
_ => {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,7 +279,7 @@ fn register_builtins(store: &mut LintStore) {
|
||||||
store.register_lints(&BuiltinCombinedEarlyLintPass::get_lints());
|
store.register_lints(&BuiltinCombinedEarlyLintPass::get_lints());
|
||||||
store.register_lints(&BuiltinCombinedModuleLateLintPass::get_lints());
|
store.register_lints(&BuiltinCombinedModuleLateLintPass::get_lints());
|
||||||
store.register_lints(&foreign_modules::get_lints());
|
store.register_lints(&foreign_modules::get_lints());
|
||||||
store.register_lints(&HardwiredLints::default().get_lints());
|
store.register_lints(&HardwiredLints::lint_vec());
|
||||||
|
|
||||||
add_lint_group!(
|
add_lint_group!(
|
||||||
"nonstandard_style",
|
"nonstandard_style",
|
||||||
|
@ -601,25 +601,25 @@ fn register_builtins(store: &mut LintStore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_internals(store: &mut LintStore) {
|
fn register_internals(store: &mut LintStore) {
|
||||||
store.register_lints(&LintPassImpl::default().get_lints());
|
store.register_lints(&LintPassImpl::lint_vec());
|
||||||
store.register_early_pass(|| Box::new(LintPassImpl));
|
store.register_early_pass(|| Box::new(LintPassImpl));
|
||||||
store.register_lints(&DefaultHashTypes::default().get_lints());
|
store.register_lints(&DefaultHashTypes::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
|
store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
|
||||||
store.register_lints(&QueryStability::default().get_lints());
|
store.register_lints(&QueryStability::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(QueryStability));
|
store.register_late_mod_pass(|_| Box::new(QueryStability));
|
||||||
store.register_lints(&ExistingDocKeyword::default().get_lints());
|
store.register_lints(&ExistingDocKeyword::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
|
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
|
||||||
store.register_lints(&TyTyKind::default().get_lints());
|
store.register_lints(&TyTyKind::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(TyTyKind));
|
store.register_late_mod_pass(|_| Box::new(TyTyKind));
|
||||||
store.register_lints(&TypeIr::default().get_lints());
|
store.register_lints(&TypeIr::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(TypeIr));
|
store.register_late_mod_pass(|_| Box::new(TypeIr));
|
||||||
store.register_lints(&Diagnostics::default().get_lints());
|
store.register_lints(&Diagnostics::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(Diagnostics));
|
store.register_late_mod_pass(|_| Box::new(Diagnostics));
|
||||||
store.register_lints(&BadOptAccess::default().get_lints());
|
store.register_lints(&BadOptAccess::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(BadOptAccess));
|
store.register_late_mod_pass(|_| Box::new(BadOptAccess));
|
||||||
store.register_lints(&PassByValue::default().get_lints());
|
store.register_lints(&PassByValue::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(PassByValue));
|
store.register_late_mod_pass(|_| Box::new(PassByValue));
|
||||||
store.register_lints(&SpanUseEqCtxt::default().get_lints());
|
store.register_lints(&SpanUseEqCtxt::lint_vec());
|
||||||
store.register_late_mod_pass(|_| Box::new(SpanUseEqCtxt));
|
store.register_late_mod_pass(|_| Box::new(SpanUseEqCtxt));
|
||||||
// FIXME(davidtwco): deliberately do not include `UNTRANSLATABLE_DIAGNOSTIC` and
|
// FIXME(davidtwco): deliberately do not include `UNTRANSLATABLE_DIAGNOSTIC` and
|
||||||
// `DIAGNOSTIC_OUTSIDE_OF_IMPL` here because `-Wrustc::internal` is provided to every crate and
|
// `DIAGNOSTIC_OUTSIDE_OF_IMPL` here because `-Wrustc::internal` is provided to every crate and
|
||||||
|
|
|
@ -70,18 +70,7 @@ macro_rules! declare_late_lint_pass {
|
||||||
// for all the `check_*` methods.
|
// for all the `check_*` methods.
|
||||||
late_lint_methods!(declare_late_lint_pass, []);
|
late_lint_methods!(declare_late_lint_pass, []);
|
||||||
|
|
||||||
impl LateLintPass<'_> for HardwiredLints {
|
impl LateLintPass<'_> for HardwiredLints {}
|
||||||
fn check_fn(
|
|
||||||
&mut self,
|
|
||||||
_: &LateContext<'_>,
|
|
||||||
_: rustc_hir::intravisit::FnKind<'_>,
|
|
||||||
_: &'_ rustc_hir::FnDecl<'_>,
|
|
||||||
_: &'_ rustc_hir::Body<'_>,
|
|
||||||
_: rustc_span::Span,
|
|
||||||
_: rustc_span::def_id::LocalDefId,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! expand_combined_late_lint_pass_method {
|
macro_rules! expand_combined_late_lint_pass_method {
|
||||||
|
@ -121,7 +110,7 @@ macro_rules! declare_combined_late_lint_pass {
|
||||||
|
|
||||||
$v fn get_lints() -> $crate::LintVec {
|
$v fn get_lints() -> $crate::LintVec {
|
||||||
let mut lints = Vec::new();
|
let mut lints = Vec::new();
|
||||||
$(lints.extend_from_slice(&$pass::default().get_lints());)*
|
$(lints.extend_from_slice(&$pass::lint_vec());)*
|
||||||
lints
|
lints
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,7 +225,7 @@ macro_rules! declare_combined_early_lint_pass {
|
||||||
|
|
||||||
$v fn get_lints() -> $crate::LintVec {
|
$v fn get_lints() -> $crate::LintVec {
|
||||||
let mut lints = Vec::new();
|
let mut lints = Vec::new();
|
||||||
$(lints.extend_from_slice(&$pass::default().get_lints());)*
|
$(lints.extend_from_slice(&$pass::lint_vec());)*
|
||||||
lints
|
lints
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ use rustc_span::edition::Edition;
|
||||||
use crate::{FutureIncompatibilityReason, declare_lint, declare_lint_pass};
|
use crate::{FutureIncompatibilityReason, declare_lint, declare_lint_pass};
|
||||||
|
|
||||||
declare_lint_pass! {
|
declare_lint_pass! {
|
||||||
|
/// Does nothing as a lint pass, but registers some `Lint`s
|
||||||
|
/// that are used by other parts of the compiler.
|
||||||
HardwiredLints => [
|
HardwiredLints => [
|
||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
|
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
|
||||||
|
@ -377,7 +379,7 @@ declare_lint! {
|
||||||
pub ARITHMETIC_OVERFLOW,
|
pub ARITHMETIC_OVERFLOW,
|
||||||
Deny,
|
Deny,
|
||||||
"arithmetic operation overflows",
|
"arithmetic operation overflows",
|
||||||
[loadbearing: true]
|
@eval_always = true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
|
@ -402,7 +404,7 @@ declare_lint! {
|
||||||
pub UNCONDITIONAL_PANIC,
|
pub UNCONDITIONAL_PANIC,
|
||||||
Deny,
|
Deny,
|
||||||
"operation will cause a panic at runtime",
|
"operation will cause a panic at runtime",
|
||||||
[loadbearing: true]
|
@eval_always = true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
|
@ -634,7 +636,7 @@ declare_lint! {
|
||||||
pub UNKNOWN_LINTS,
|
pub UNKNOWN_LINTS,
|
||||||
Warn,
|
Warn,
|
||||||
"unrecognized lint attribute",
|
"unrecognized lint attribute",
|
||||||
[loadbearing: true]
|
@eval_always = true
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
|
|
|
@ -315,7 +315,7 @@ pub struct Lint {
|
||||||
|
|
||||||
/// `true` if this lint should not be filtered out under any circustamces
|
/// `true` if this lint should not be filtered out under any circustamces
|
||||||
/// (e.g. the unknown_attributes lint)
|
/// (e.g. the unknown_attributes lint)
|
||||||
pub loadbearing: bool,
|
pub eval_always: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extra information for a future incompatibility lint.
|
/// Extra information for a future incompatibility lint.
|
||||||
|
@ -460,7 +460,7 @@ impl Lint {
|
||||||
future_incompatible: None,
|
future_incompatible: None,
|
||||||
feature_gate: None,
|
feature_gate: None,
|
||||||
crate_level_only: false,
|
crate_level_only: false,
|
||||||
loadbearing: false,
|
eval_always: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,7 +868,8 @@ macro_rules! declare_lint {
|
||||||
$(#[$attr])* $vis $NAME, $Level, $desc,
|
$(#[$attr])* $vis $NAME, $Level, $desc,
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr, $([loadbearing: $loadbearing: literal])?
|
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
|
||||||
|
$(@eval_always = $eval_always:literal)?
|
||||||
$(@feature_gate = $gate:ident;)?
|
$(@feature_gate = $gate:ident;)?
|
||||||
$(@future_incompatible = FutureIncompatibleInfo {
|
$(@future_incompatible = FutureIncompatibleInfo {
|
||||||
reason: $reason:expr,
|
reason: $reason:expr,
|
||||||
|
@ -890,7 +891,7 @@ macro_rules! declare_lint {
|
||||||
..$crate::FutureIncompatibleInfo::default_fields_for_macro()
|
..$crate::FutureIncompatibleInfo::default_fields_for_macro()
|
||||||
}),)?
|
}),)?
|
||||||
$(edition_lint_opts: Some(($crate::Edition::$lint_edition, $crate::$edition_level)),)?
|
$(edition_lint_opts: Some(($crate::Edition::$lint_edition, $crate::$edition_level)),)?
|
||||||
$(loadbearing: $loadbearing,)?
|
$(eval_always: $eval_always,)?
|
||||||
..$crate::Lint::default_fields_for_macro()
|
..$crate::Lint::default_fields_for_macro()
|
||||||
};
|
};
|
||||||
);
|
);
|
||||||
|
@ -900,8 +901,8 @@ macro_rules! declare_lint {
|
||||||
macro_rules! declare_tool_lint {
|
macro_rules! declare_tool_lint {
|
||||||
(
|
(
|
||||||
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
|
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
|
||||||
|
$(, @eval_always = $eval_always:literal)?
|
||||||
$(, @feature_gate = $gate:ident;)?
|
$(, @feature_gate = $gate:ident;)?
|
||||||
$(, [loadbearing: $loadbearing: literal])?
|
|
||||||
) => (
|
) => (
|
||||||
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @feature_gate = $gate;)?}
|
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @feature_gate = $gate;)?}
|
||||||
);
|
);
|
||||||
|
@ -909,15 +910,15 @@ macro_rules! declare_tool_lint {
|
||||||
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
||||||
report_in_external_macro: $rep:expr
|
report_in_external_macro: $rep:expr
|
||||||
$(, @feature_gate = $gate:ident;)?
|
$(, @feature_gate = $gate:ident;)?
|
||||||
$(, [loadbearing: $loadbearing: literal])?
|
$(, eval_always: $eval_always: literal)?
|
||||||
) => (
|
) => (
|
||||||
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @feature_gate = $gate;)?}
|
$crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @feature_gate = $gate;)?}
|
||||||
);
|
);
|
||||||
(
|
(
|
||||||
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
|
||||||
$external:expr
|
$external:expr
|
||||||
|
$(, @eval_always: $eval_always: literal)?
|
||||||
$(, @feature_gate = $gate:ident;)?
|
$(, @feature_gate = $gate:ident;)?
|
||||||
$(, [loadbearing: $loadbearing: literal])?
|
|
||||||
) => (
|
) => (
|
||||||
$(#[$attr])*
|
$(#[$attr])*
|
||||||
$vis static $NAME: &$crate::Lint = &$crate::Lint {
|
$vis static $NAME: &$crate::Lint = &$crate::Lint {
|
||||||
|
@ -930,7 +931,7 @@ macro_rules! declare_tool_lint {
|
||||||
is_externally_loaded: true,
|
is_externally_loaded: true,
|
||||||
$(feature_gate: Some(rustc_span::symbol::sym::$gate),)?
|
$(feature_gate: Some(rustc_span::symbol::sym::$gate),)?
|
||||||
crate_level_only: false,
|
crate_level_only: false,
|
||||||
$(loadbearing: $loadbearing,)?
|
$(eval_always: $eval_always,)?
|
||||||
..$crate::Lint::default_fields_for_macro()
|
..$crate::Lint::default_fields_for_macro()
|
||||||
};
|
};
|
||||||
);
|
);
|
||||||
|
@ -951,6 +952,10 @@ macro_rules! impl_lint_pass {
|
||||||
fn name(&self) -> &'static str { stringify!($ty) }
|
fn name(&self) -> &'static str { stringify!($ty) }
|
||||||
fn get_lints(&self) -> $crate::LintVec { vec![$($lint),*] }
|
fn get_lints(&self) -> $crate::LintVec { vec![$($lint),*] }
|
||||||
}
|
}
|
||||||
|
impl $ty {
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn lint_vec() -> $crate::LintVec { vec![$($lint),*] }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -959,7 +964,7 @@ macro_rules! impl_lint_pass {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! declare_lint_pass {
|
macro_rules! declare_lint_pass {
|
||||||
($(#[$m:meta])* $name:ident => [$($lint:expr),* $(,)?]) => {
|
($(#[$m:meta])* $name:ident => [$($lint:expr),* $(,)?]) => {
|
||||||
$(#[$m])* #[derive(Copy, Clone, Default)] pub struct $name;
|
$(#[$m])* #[derive(Copy, Clone)] pub struct $name;
|
||||||
$crate::impl_lint_pass!($name => [$($lint),*]);
|
$crate::impl_lint_pass!($name => [$($lint),*]);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl ShallowLintLevelMap {
|
||||||
/// This lint level is not usable for diagnostics, it needs to be corrected by
|
/// This lint level is not usable for diagnostics, it needs to be corrected by
|
||||||
/// `reveal_actual_level` beforehand.
|
/// `reveal_actual_level` beforehand.
|
||||||
#[instrument(level = "trace", skip(self, tcx), ret)]
|
#[instrument(level = "trace", skip(self, tcx), ret)]
|
||||||
pub fn probe_for_lint_level(
|
fn probe_for_lint_level(
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
id: LintId,
|
id: LintId,
|
||||||
|
|
|
@ -187,7 +187,6 @@ pub struct Session {
|
||||||
/// errors.
|
/// errors.
|
||||||
pub ctfe_backtrace: Lock<CtfeBacktrace>,
|
pub ctfe_backtrace: Lock<CtfeBacktrace>,
|
||||||
|
|
||||||
// pub force_ctfe: bool,
|
|
||||||
/// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a
|
/// This tracks where `-Zunleash-the-miri-inside-of-you` was used to get around a
|
||||||
/// const check, optionally with the relevant feature gate. We use this to
|
/// const check, optionally with the relevant feature gate. We use this to
|
||||||
/// warn about unleashing, but with a single diagnostic instead of dozens that
|
/// warn about unleashing, but with a single diagnostic instead of dozens that
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::LazyLock as Lazy;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_lint::LintStore;
|
use rustc_lint::LintStore;
|
||||||
use rustc_lint_defs::{Lint, LintId, LintPass, declare_tool_lint};
|
use rustc_lint_defs::{Lint, LintId, declare_tool_lint};
|
||||||
use rustc_session::{Session, lint};
|
use rustc_session::{Session, lint};
|
||||||
|
|
||||||
/// This function is used to setup the lint initialization. By default, in rustdoc, everything
|
/// This function is used to setup the lint initialization. By default, in rustdoc, everything
|
||||||
|
@ -31,10 +31,9 @@ where
|
||||||
allowed_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned());
|
allowed_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned());
|
||||||
|
|
||||||
let lints = || {
|
let lints = || {
|
||||||
lint::builtin::HardwiredLints::default()
|
lint::builtin::HardwiredLints::lint_vec()
|
||||||
.get_lints()
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(rustc_lint::SoftLints::default().get_lints())
|
.chain(rustc_lint::SoftLints::lint_vec())
|
||||||
};
|
};
|
||||||
|
|
||||||
let lint_opts = lints()
|
let lint_opts = lints()
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub static COGNITIVE_COMPLEXITY: &Lint = &Lint {
|
||||||
future_incompatible: None,
|
future_incompatible: None,
|
||||||
is_externally_loaded: true,
|
is_externally_loaded: true,
|
||||||
crate_level_only: false,
|
crate_level_only: false,
|
||||||
loadbearing: true,
|
eval_always: true,
|
||||||
..Lint::default_fields_for_macro()
|
..Lint::default_fields_for_macro()
|
||||||
};
|
};
|
||||||
pub(crate) static COGNITIVE_COMPLEXITY_INFO: &'static LintInfo = &LintInfo {
|
pub(crate) static COGNITIVE_COMPLEXITY_INFO: &'static LintInfo = &LintInfo {
|
||||||
|
@ -44,7 +44,7 @@ Sometimes it's hard to find a way to reduce the complexity.
|
||||||
### Example
|
### Example
|
||||||
You'll see it when you get the warning.",
|
You'll see it when you get the warning.",
|
||||||
version: Some("1.35.0"),
|
version: Some("1.35.0"),
|
||||||
location: "#L0",
|
location: "clippy_lints/src/cognitive_complexity.rs#L47",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct CognitiveComplexity {
|
pub struct CognitiveComplexity {
|
||||||
|
|
|
@ -1,41 +1,28 @@
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{Body, FnDecl};
|
use rustc_hir::{Body, FnDecl};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::Level::Deny;
|
||||||
|
use rustc_lint::{LateContext, LateLintPass, Lint};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
/// Ensures that Constant-time Function Evaluation is being done (specifically, MIR lint passes).
|
||||||
/// ### What it does
|
/// See rust-lang/rust#125116 for more info.
|
||||||
/// Checks for comparisons where one side of the relation is
|
#[clippy::version = "1.82.0"]
|
||||||
/// either the minimum or maximum value for its type and warns if it involves a
|
pub static CLIPPY_CTFE: &Lint = &Lint {
|
||||||
/// case that is always true or always false. Only integer and boolean types are
|
name: &"clippy::CLIPPY_CTFE",
|
||||||
/// checked.
|
default_level: Deny,
|
||||||
///
|
desc: "Ensure CTFE is being made",
|
||||||
/// ### Why is this bad?
|
edition_lint_opts: None,
|
||||||
/// An expression like `min <= x` may misleadingly imply
|
report_in_external_macro: true,
|
||||||
/// that it is possible for `x` to be less than the minimum. Expressions like
|
future_incompatible: None,
|
||||||
/// `max < x` are probably mistakes.
|
is_externally_loaded: true,
|
||||||
///
|
crate_level_only: false,
|
||||||
/// ### Known problems
|
eval_always: true,
|
||||||
/// For `usize` the size of the current compile target will
|
..Lint::default_fields_for_macro()
|
||||||
/// be assumed (e.g., 64 bits on 64 bit systems). This means code that uses such
|
};
|
||||||
/// a comparison to detect target pointer width will trigger this lint. One can
|
|
||||||
/// use `mem::sizeof` and compare its value or conditional compilation
|
// No static CLIPPY_CTFE_INFO because we want this lint to be invisible
|
||||||
/// attributes
|
|
||||||
/// like `#[cfg(target_pointer_width = "64")] ..` instead.
|
|
||||||
///
|
|
||||||
/// ### Example
|
|
||||||
/// ```no_run
|
|
||||||
/// let vec: Vec<isize> = Vec::new();
|
|
||||||
/// if vec.len() <= 0 {}
|
|
||||||
/// if 100 > i32::MAX {}
|
|
||||||
/// ```
|
|
||||||
#[clippy::version = "1.82.0"]
|
|
||||||
pub CLIPPY_CTFE,
|
|
||||||
correctness,
|
|
||||||
"a comparison with a maximum or minimum value that is always true or false"
|
|
||||||
}
|
|
||||||
|
|
||||||
declare_lint_pass! { ClippyCtfe => [CLIPPY_CTFE] }
|
declare_lint_pass! { ClippyCtfe => [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 (rust#125116)
|
||||||
pub mod declared_lints;
|
pub mod declared_lints;
|
||||||
pub mod deprecated_lints;
|
pub mod deprecated_lints;
|
||||||
|
|
||||||
|
|
|
@ -798,4 +798,3 @@ fn path_to_string(path: &QPath<'_>) -> Result<String, ()> {
|
||||||
inner(&mut s, path)?;
|
inner(&mut s, path)?;
|
||||||
Ok(s)
|
Ok(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue