Skip to content

Commit 79cf5e4

Browse files
committed
Auto merge of #67788 - cjgillot:delint-day, r=Zoxc
Move early and late lint mechanisms to librustc_lint. As requested, split from #67737 r? @Zoxc
2 parents abf2e00 + 1fab03e commit 79cf5e4

File tree

8 files changed

+1011
-944
lines changed

8 files changed

+1011
-944
lines changed

src/librustc/lint/context.rs

+15-814
Large diffs are not rendered by default.

src/librustc/lint/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub struct LintLevelsBuilder<'a> {
155155

156156
pub struct BuilderPush {
157157
prev: u32,
158-
pub(super) changed: bool,
158+
pub changed: bool,
159159
}
160160

161161
impl<'a> LintLevelsBuilder<'a> {

src/librustc/lint/mod.rs

+4-124
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ pub use self::LintSource::*;
2424
use rustc_data_structures::sync;
2525

2626
use crate::hir;
27-
use crate::hir::def_id::{CrateNum, LOCAL_CRATE};
28-
use crate::hir::intravisit;
2927
use crate::lint::builtin::BuiltinLintDiagnostics;
3028
use crate::session::{DiagnosticMessageId, Session};
31-
use crate::ty::query::Providers;
3229
use crate::ty::TyCtxt;
3330
use crate::util::nodemap::NodeMap;
3431
use errors::{DiagnosticBuilder, DiagnosticId};
@@ -39,8 +36,7 @@ use rustc_span::Span;
3936
use syntax::ast;
4037

4138
pub use crate::lint::context::{
42-
check_ast_crate, check_crate, late_lint_mod, BufferedEarlyLint, CheckLintNameResult,
43-
EarlyContext, LateContext, LintContext, LintStore,
39+
BufferedEarlyLint, CheckLintNameResult, EarlyContext, LateContext, LintContext, LintStore,
4440
};
4541

4642
pub use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintId};
@@ -376,11 +372,11 @@ mod context;
376372
pub mod internal;
377373
mod levels;
378374

379-
pub use self::levels::{LintLevelMap, LintLevelSets};
375+
pub use self::levels::{LintLevelMap, LintLevelSets, LintLevelsBuilder};
380376

381377
#[derive(Default)]
382378
pub struct LintBuffer {
383-
map: NodeMap<Vec<BufferedEarlyLint>>,
379+
pub map: NodeMap<Vec<BufferedEarlyLint>>,
384380
}
385381

386382
impl LintBuffer {
@@ -405,7 +401,7 @@ impl LintBuffer {
405401
}
406402
}
407403

408-
fn take(&mut self, id: ast::NodeId) -> Vec<BufferedEarlyLint> {
404+
pub fn take(&mut self, id: ast::NodeId) -> Vec<BufferedEarlyLint> {
409405
self.map.remove(&id).unwrap_or_default()
410406
}
411407

@@ -564,122 +560,6 @@ pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
564560
attrs.iter().any(|attr| Level::from_symbol(attr.name_or_empty()).is_some())
565561
}
566562

567-
fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> &LintLevelMap {
568-
assert_eq!(cnum, LOCAL_CRATE);
569-
let store = &tcx.lint_store;
570-
let mut builder = LintLevelMapBuilder {
571-
levels: LintLevelSets::builder(tcx.sess, false, &store),
572-
tcx: tcx,
573-
store: store,
574-
};
575-
let krate = tcx.hir().krate();
576-
577-
let push = builder.levels.push(&krate.attrs, &store);
578-
builder.levels.register_id(hir::CRATE_HIR_ID);
579-
for macro_def in krate.exported_macros {
580-
builder.levels.register_id(macro_def.hir_id);
581-
}
582-
intravisit::walk_crate(&mut builder, krate);
583-
builder.levels.pop(push);
584-
585-
tcx.arena.alloc(builder.levels.build_map())
586-
}
587-
588-
struct LintLevelMapBuilder<'a, 'tcx> {
589-
levels: levels::LintLevelsBuilder<'tcx>,
590-
tcx: TyCtxt<'tcx>,
591-
store: &'a LintStore,
592-
}
593-
594-
impl LintLevelMapBuilder<'_, '_> {
595-
fn with_lint_attrs<F>(&mut self, id: hir::HirId, attrs: &[ast::Attribute], f: F)
596-
where
597-
F: FnOnce(&mut Self),
598-
{
599-
let push = self.levels.push(attrs, self.store);
600-
if push.changed {
601-
self.levels.register_id(id);
602-
}
603-
f(self);
604-
self.levels.pop(push);
605-
}
606-
}
607-
608-
impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
609-
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
610-
intravisit::NestedVisitorMap::All(&self.tcx.hir())
611-
}
612-
613-
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
614-
self.with_lint_attrs(param.hir_id, &param.attrs, |builder| {
615-
intravisit::walk_param(builder, param);
616-
});
617-
}
618-
619-
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
620-
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| {
621-
intravisit::walk_item(builder, it);
622-
});
623-
}
624-
625-
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
626-
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| {
627-
intravisit::walk_foreign_item(builder, it);
628-
})
629-
}
630-
631-
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
632-
self.with_lint_attrs(e.hir_id, &e.attrs, |builder| {
633-
intravisit::walk_expr(builder, e);
634-
})
635-
}
636-
637-
fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) {
638-
self.with_lint_attrs(s.hir_id, &s.attrs, |builder| {
639-
intravisit::walk_struct_field(builder, s);
640-
})
641-
}
642-
643-
fn visit_variant(
644-
&mut self,
645-
v: &'tcx hir::Variant<'tcx>,
646-
g: &'tcx hir::Generics<'tcx>,
647-
item_id: hir::HirId,
648-
) {
649-
self.with_lint_attrs(v.id, &v.attrs, |builder| {
650-
intravisit::walk_variant(builder, v, g, item_id);
651-
})
652-
}
653-
654-
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
655-
self.with_lint_attrs(l.hir_id, &l.attrs, |builder| {
656-
intravisit::walk_local(builder, l);
657-
})
658-
}
659-
660-
fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) {
661-
self.with_lint_attrs(a.hir_id, &a.attrs, |builder| {
662-
intravisit::walk_arm(builder, a);
663-
})
664-
}
665-
666-
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
667-
self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| {
668-
intravisit::walk_trait_item(builder, trait_item);
669-
});
670-
}
671-
672-
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
673-
self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| {
674-
intravisit::walk_impl_item(builder, impl_item);
675-
});
676-
}
677-
}
678-
679-
pub fn provide(providers: &mut Providers<'_>) {
680-
providers.lint_levels = lint_levels;
681-
}
682-
683563
/// Returns whether `span` originates in a foreign crate's external macro.
684564
///
685565
/// This is used to test whether a lint should not even begin to figure out whether it should

src/librustc_interface/passes.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ fn configure_and_expand_inner<'a>(
231231
metadata_loader: &'a MetadataLoaderDyn,
232232
) -> Result<(ast::Crate, Resolver<'a>)> {
233233
time(sess, "pre-AST-expansion lint checks", || {
234-
lint::check_ast_crate(
234+
rustc_lint::check_ast_crate(
235235
sess,
236236
lint_store,
237237
&krate,
@@ -458,7 +458,7 @@ pub fn lower_to_hir<'res, 'tcx>(
458458
});
459459

460460
time(sess, "early lint checks", || {
461-
lint::check_ast_crate(
461+
rustc_lint::check_ast_crate(
462462
sess,
463463
lint_store,
464464
&krate,
@@ -691,7 +691,6 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
691691
rustc_resolve::provide(providers);
692692
rustc_traits::provide(providers);
693693
rustc_metadata::provide(providers);
694-
lint::provide(providers);
695694
rustc_lint::provide(providers);
696695
rustc_codegen_utils::provide(providers);
697696
rustc_codegen_ssa::provide(providers);
@@ -885,7 +884,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
885884
},
886885
{
887886
time(sess, "lint checking", || {
888-
lint::check_crate(tcx, || {
887+
rustc_lint::check_crate(tcx, || {
889888
rustc_lint::BuiltinCombinedLateLintPass::new()
890889
});
891890
});

0 commit comments

Comments
 (0)