Skip to content

Commit 637d5cc

Browse files
committed
Remove module passes filtering
1 parent 71b4d10 commit 637d5cc

File tree

16 files changed

+111
-214
lines changed

16 files changed

+111
-214
lines changed

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
972972
tcx.ensure().check_mod_privacy(module);
973973
});
974974
});
975-
} // { sess.time("mir_checking", || { tcx.hir().mir_for }) }
975+
}
976976
);
977977

978978
// This check has to be run after all lints are done processing. We don't

compiler/rustc_lint/src/builtin.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
//! If you define a new `LateLintPass`, you will also need to add it to the
2121
//! `late_lint_methods!` invocation in `lib.rs`.
2222
23-
use std::default::Default;
2423
use std::fmt::Write;
2524

2625
use ast::token::TokenKind;
@@ -74,11 +73,6 @@ use crate::{
7473
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
7574
fluent_generated as fluent,
7675
};
77-
// use std::fmt::Write;
78-
79-
// hardwired lints from rustc_lint_defs
80-
// pub use rustc_session::lint::builtin::*;
81-
8276
declare_lint! {
8377
/// The `while_true` lint detects `while true { }`.
8478
///
@@ -247,7 +241,7 @@ declare_lint! {
247241
UNSAFE_CODE,
248242
Allow,
249243
"usage of `unsafe` code and other potentially unsound constructs",
250-
[loadbearing: true]
244+
@eval_always = true
251245
}
252246

253247
declare_lint_pass!(UnsafeCode => [UNSAFE_CODE]);

compiler/rustc_lint/src/internal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ declare_tool_lint! {
430430
Deny,
431431
"prevent creation of diagnostics which cannot be translated",
432432
report_in_external_macro: true,
433-
[loadbearing: true]
433+
eval_always: true
434434
}
435435

436436
declare_tool_lint! {
@@ -444,7 +444,7 @@ declare_tool_lint! {
444444
Deny,
445445
"prevent diagnostic creation outside of `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls",
446446
report_in_external_macro: true,
447-
[loadbearing: true]
447+
eval_always: true
448448
}
449449

450450
declare_lint_pass!(Diagnostics => [UNTRANSLATABLE_DIAGNOSTIC, DIAGNOSTIC_OUTSIDE_OF_IMPL]);

compiler/rustc_lint/src/late.rs

+12-35
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use rustc_hir::def_id::{LocalDefId, LocalModDefId};
2424
use rustc_hir::{HirId, intravisit as hir_visit};
2525
use rustc_middle::hir::nested_filter;
2626
use rustc_middle::ty::{self, TyCtxt};
27-
use rustc_session::{Session, lint::{LintPass, builtin::HardwiredLints}};
27+
use rustc_session::Session;
28+
use rustc_session::lint::LintPass;
29+
use rustc_session::lint::builtin::HardwiredLints;
2830
use rustc_span::Span;
2931
use tracing::debug;
3032

@@ -368,28 +370,15 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
368370
if store.late_module_passes.is_empty() {
369371
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
370372
} else {
371-
let passes: Vec<_> =
372-
store.late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
373-
// Filter unused lints
374-
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
375-
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
376-
.into_iter()
377-
.filter(|pass| {
378-
let lints = LintPass::get_lints(pass);
379-
if lints.is_empty() {
380-
true
381-
} else {
382-
lints
383-
.iter()
384-
.any(|lint| !lints_that_dont_need_to_run.contains(&LintId::of(lint)))
385-
}
386-
})
387-
.collect();
388-
389-
filtered_passes.push(Box::new(builtin_lints));
390-
filtered_passes.push(Box::new(HardwiredLints));
391-
392-
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
373+
let builtin_lints = Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>;
374+
let mut binding = store
375+
.late_module_passes
376+
.iter()
377+
.map(|mk_pass| (mk_pass)(tcx))
378+
.chain(std::iter::once(builtin_lints))
379+
.collect::<Vec<_>>();
380+
381+
let pass = RuntimeCombinedLateLintPass { passes: binding.as_mut_slice() };
393382
late_lint_mod_inner(tcx, module_def_id, context, pass);
394383
}
395384
}
@@ -440,7 +429,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
440429

441430
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
442431

443-
// dbg!(&lints_that_dont_need_to_run);
444432
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
445433
.into_iter()
446434
.filter(|pass| {
@@ -450,17 +438,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
450438
.collect();
451439

452440
filtered_passes.push(Box::new(HardwiredLints));
453-
454-
// let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
455-
// .into_iter()
456-
// .filter(|pass| {
457-
// let lints = LintPass::get_lints(pass);
458-
// lints.iter()
459-
// .any(|lint|
460-
// !lints_that_dont_need_to_run.contains(&LintId::of(lint)))
461-
// }).collect();
462-
//
463-
464441
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
465442
late_lint_crate_inner(tcx, context, pass);
466443
}

compiler/rustc_lint/src/levels.rs

+36-90
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::errors::{
3131
OverruledAttributeSub, RequestedLevel, UnknownToolInScopedLint, UnsupportedGroup,
3232
};
3333
use crate::fluent_generated as fluent;
34-
use crate::late::{unerased_lint_store /*name_without_tool*/};
34+
use crate::late::unerased_lint_store;
3535
use crate::lints::{
3636
DeprecatedLintName, DeprecatedLintNameFromCommandLine, IgnoredUnlessCrateSpecified,
3737
OverruledAttributeLint, RemovedLint, RemovedLintFromCommandLine, RenamedLint,
@@ -122,7 +122,7 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
122122
.get_lints()
123123
.into_iter()
124124
.filter_map(|lint| {
125-
if !lint.loadbearing && lint.default_level(tcx.sess.edition()) == Level::Allow {
125+
if !lint.eval_always && lint.default_level(tcx.sess.edition()) == Level::Allow {
126126
Some(LintId::of(lint))
127127
} else {
128128
None
@@ -134,21 +134,6 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
134134
visitor.process_opts();
135135
tcx.hir().walk_attributes(&mut visitor);
136136

137-
// let lint_groups = store.get_lint_groups();
138-
// for group in lint_groups {
139-
// let binding = group.0.to_lowercase();
140-
// let group_name = name_without_tool(&binding).to_string();
141-
// if visitor.lints_that_actually_run.contains(&group_name) {
142-
// for lint in group.1 {
143-
// visitor.lints_that_actually_run.insert(name_without_tool(&lint.to_string()).to_string());
144-
// }
145-
// } else if visitor.lints_allowed.contains(&group_name) {
146-
// for lint in &group.1 {
147-
// visitor.lints_allowed.insert(name_without_tool(&lint.to_string()).to_string());
148-
// }
149-
// }
150-
// }
151-
152137
visitor.dont_need_to_run
153138
}
154139

@@ -372,83 +357,44 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
372357
self.tcx.hir()
373358
}
374359

360+
/// FIXME(blyxyas): In a future revision, we should also graph #![allow]s,
361+
/// but that is handled with more care
375362
fn visit_attribute(&mut self, attribute: &'tcx ast::Attribute) {
376-
match Level::from_attr(attribute) {
363+
if matches!(
364+
Level::from_attr(attribute),
377365
Some(
378366
Level::Warn
379-
| Level::Deny
380-
| Level::Forbid
381-
| Level::Expect(..)
382-
| Level::ForceWarn(..),
383-
) => {
384-
let store = unerased_lint_store(self.tcx.sess);
385-
let Some(meta) = attribute.meta() else { return };
386-
// SAFETY: Lint attributes are always a metalist inside a
387-
// metalist (even with just one lint).
388-
let Some(meta_item_list) = meta.meta_item_list() else { return };
389-
390-
for meta_list in meta_item_list {
391-
// Convert Path to String
392-
let Some(meta_item) = meta_list.meta_item() else { return };
393-
let ident: &str = &meta_item
394-
.path
395-
.segments
396-
.iter()
397-
.map(|segment| segment.ident.as_str())
398-
.collect::<Vec<&str>>()
399-
.join("::");
400-
let Ok(lints) = store.find_lints(
401-
// SAFETY: Lint attributes can only have literals
402-
ident,
403-
) else {
404-
return;
405-
};
406-
for lint in lints {
407-
self.dont_need_to_run.swap_remove(&lint);
408-
}
409-
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
410-
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
411-
// if meta_item.path.segments.len() == 1 {
412-
// let Ok(lints) = store.find_lints(
413-
// // SAFETY: Lint attributes can only have literals
414-
// meta_list.ident().unwrap().name.as_str(),
415-
// ) else {
416-
// return;
417-
// };
418-
// for lint in lints {
419-
// dbg!("LINT REMOVED", &lint);
420-
// self.dont_need_to_run.swap_remove(&lint);
421-
// }
422-
// } else {
423-
// let Ok(lints) = store.find_lints(
424-
// // SAFETY: Lint attributes can only have literals
425-
// meta_item.path.segments[1].ident.name.as_str(),
426-
// ) else {
427-
// return;
428-
// };
429-
// for lint in lints {
430-
// dbg!("LINT REMOVED", &lint);
431-
// self.dont_need_to_run.swap_remove(&lint);
432-
// }
433-
// }
367+
| Level::Deny
368+
| Level::Forbid
369+
| Level::Expect(..)
370+
| Level::ForceWarn(..),
371+
)
372+
) {
373+
let store = unerased_lint_store(self.tcx.sess);
374+
let Some(meta) = attribute.meta() else { return };
375+
// SAFETY: Lint attributes are always a metalist inside a
376+
// metalist (even with just one lint).
377+
let Some(meta_item_list) = meta.meta_item_list() else { return };
378+
379+
for meta_list in meta_item_list {
380+
// Convert Path to String
381+
let Some(meta_item) = meta_list.meta_item() else { return };
382+
let ident: &str = &meta_item
383+
.path
384+
.segments
385+
.iter()
386+
.map(|segment| segment.ident.as_str())
387+
.collect::<Vec<&str>>()
388+
.join("::");
389+
let Ok(lints) = store.find_lints(
390+
// SAFETY: Lint attributes can only have literals
391+
ident,
392+
) else {
393+
return;
394+
};
395+
for lint in lints {
396+
self.dont_need_to_run.swap_remove(&lint);
434397
}
435-
// We handle #![allow]s differently, as these remove checking rather than adding.
436-
} // Some(Level::Allow) if ast::AttrStyle::Inner == attribute.style => {
437-
// for meta_list in meta.meta_item_list().unwrap() {
438-
// // If it's a tool lint (e.g. clippy::my_clippy_lint)
439-
// if let ast::NestedMetaItem::MetaItem(meta_item) = meta_list {
440-
// if meta_item.path.segments.len() == 1 {
441-
// self.lints_allowed
442-
// .insert(meta_list.name_or_empty().as_str().to_string());
443-
// } else {
444-
// self.lints_allowed
445-
// .insert(meta_item.path.segments[1].ident.name.as_str().to_string());
446-
// }
447-
// }
448-
// }
449-
// }
450-
_ => {
451-
return;
452398
}
453399
}
454400
}

compiler/rustc_lint/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn register_builtins(store: &mut LintStore) {
279279
store.register_lints(&BuiltinCombinedEarlyLintPass::get_lints());
280280
store.register_lints(&BuiltinCombinedModuleLateLintPass::get_lints());
281281
store.register_lints(&foreign_modules::get_lints());
282-
store.register_lints(&HardwiredLints::default().get_lints());
282+
store.register_lints(&HardwiredLints::lint_vec());
283283

284284
add_lint_group!(
285285
"nonstandard_style",
@@ -601,25 +601,25 @@ fn register_builtins(store: &mut LintStore) {
601601
}
602602

603603
fn register_internals(store: &mut LintStore) {
604-
store.register_lints(&LintPassImpl::default().get_lints());
604+
store.register_lints(&LintPassImpl::lint_vec());
605605
store.register_early_pass(|| Box::new(LintPassImpl));
606-
store.register_lints(&DefaultHashTypes::default().get_lints());
606+
store.register_lints(&DefaultHashTypes::lint_vec());
607607
store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
608-
store.register_lints(&QueryStability::default().get_lints());
608+
store.register_lints(&QueryStability::lint_vec());
609609
store.register_late_mod_pass(|_| Box::new(QueryStability));
610-
store.register_lints(&ExistingDocKeyword::default().get_lints());
610+
store.register_lints(&ExistingDocKeyword::lint_vec());
611611
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
612-
store.register_lints(&TyTyKind::default().get_lints());
612+
store.register_lints(&TyTyKind::lint_vec());
613613
store.register_late_mod_pass(|_| Box::new(TyTyKind));
614-
store.register_lints(&TypeIr::default().get_lints());
614+
store.register_lints(&TypeIr::lint_vec());
615615
store.register_late_mod_pass(|_| Box::new(TypeIr));
616-
store.register_lints(&Diagnostics::default().get_lints());
616+
store.register_lints(&Diagnostics::lint_vec());
617617
store.register_late_mod_pass(|_| Box::new(Diagnostics));
618-
store.register_lints(&BadOptAccess::default().get_lints());
618+
store.register_lints(&BadOptAccess::lint_vec());
619619
store.register_late_mod_pass(|_| Box::new(BadOptAccess));
620-
store.register_lints(&PassByValue::default().get_lints());
620+
store.register_lints(&PassByValue::lint_vec());
621621
store.register_late_mod_pass(|_| Box::new(PassByValue));
622-
store.register_lints(&SpanUseEqCtxt::default().get_lints());
622+
store.register_lints(&SpanUseEqCtxt::lint_vec());
623623
store.register_late_mod_pass(|_| Box::new(SpanUseEqCtxt));
624624
// FIXME(davidtwco): deliberately do not include `UNTRANSLATABLE_DIAGNOSTIC` and
625625
// `DIAGNOSTIC_OUTSIDE_OF_IMPL` here because `-Wrustc::internal` is provided to every crate and

compiler/rustc_lint/src/passes.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,7 @@ macro_rules! declare_late_lint_pass {
7070
// for all the `check_*` methods.
7171
late_lint_methods!(declare_late_lint_pass, []);
7272

73-
impl LateLintPass<'_> for HardwiredLints {
74-
fn check_fn(
75-
&mut self,
76-
_: &LateContext<'_>,
77-
_: rustc_hir::intravisit::FnKind<'_>,
78-
_: &'_ rustc_hir::FnDecl<'_>,
79-
_: &'_ rustc_hir::Body<'_>,
80-
_: rustc_span::Span,
81-
_: rustc_span::def_id::LocalDefId,
82-
) {
83-
}
84-
}
73+
impl LateLintPass<'_> for HardwiredLints {}
8574

8675
#[macro_export]
8776
macro_rules! expand_combined_late_lint_pass_method {
@@ -121,7 +110,7 @@ macro_rules! declare_combined_late_lint_pass {
121110

122111
$v fn get_lints() -> $crate::LintVec {
123112
let mut lints = Vec::new();
124-
$(lints.extend_from_slice(&$pass::default().get_lints());)*
113+
$(lints.extend_from_slice(&$pass::lint_vec());)*
125114
lints
126115
}
127116
}
@@ -236,7 +225,7 @@ macro_rules! declare_combined_early_lint_pass {
236225

237226
$v fn get_lints() -> $crate::LintVec {
238227
let mut lints = Vec::new();
239-
$(lints.extend_from_slice(&$pass::default().get_lints());)*
228+
$(lints.extend_from_slice(&$pass::lint_vec());)*
240229
lints
241230
}
242231
}

0 commit comments

Comments
 (0)