diff options
Diffstat (limited to 'compiler/rustc_interface/src')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/queries.rs | 3 |
3 files changed, 12 insertions, 23 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 89125c54a6a..d113e038966 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -40,7 +40,6 @@ pub type Result<T> = result::Result<T, ErrorGuaranteed>; pub struct Compiler { pub(crate) sess: Lrc<Session>, codegen_backend: Lrc<dyn CodegenBackend>, - pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>, pub(crate) override_queries: Option<fn(&Session, &mut Providers)>, } @@ -51,9 +50,6 @@ impl Compiler { pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> { &self.codegen_backend } - pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> { - &self.register_lints - } pub fn build_output_filenames( &self, sess: &Session, @@ -485,10 +481,19 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se sess.opts.untracked_state_hash = hasher.finish() } + // Even though the session holds the lint store, we can't build the + // lint store until after the session exists. And we wait until now + // so that `register_lints` sees the fully initialized session. + let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints()); + if let Some(register_lints) = config.register_lints.as_deref() { + register_lints(&sess, &mut lint_store); + sess.registered_lints = true; + } + sess.lint_store = Some(Lrc::new(lint_store)); + let compiler = Compiler { sess: Lrc::new(sess), codegen_backend: Lrc::from(codegen_backend), - register_lints: config.register_lints, override_queries: config.override_queries, }; diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 7d14d088e59..0baf77c4f7e 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -72,17 +72,6 @@ fn count_nodes(krate: &ast::Crate) -> usize { counter.count } -pub(crate) fn create_lint_store( - sess: &Session, - register_lints: Option<impl Fn(&Session, &mut LintStore)>, -) -> LintStore { - let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints()); - if let Some(register_lints) = register_lints { - register_lints(sess, &mut lint_store); - } - lint_store -} - fn pre_expansion_lint<'a>( sess: &Session, features: &Features, @@ -138,7 +127,7 @@ fn configure_and_expand( let tcx = resolver.tcx(); let sess = tcx.sess; let features = tcx.features(); - let lint_store = unerased_lint_store(tcx); + let lint_store = unerased_lint_store(&tcx.sess); let crate_name = tcx.crate_name(LOCAL_CRATE); let lint_check_node = (&krate, pre_configured_attrs); pre_expansion_lint( @@ -330,7 +319,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { } }); - let lint_store = unerased_lint_store(tcx); + let lint_store = unerased_lint_store(&tcx.sess); rustc_lint::check_ast_node( sess, tcx.features(), @@ -645,7 +634,6 @@ pub fn create_global_ctxt<'tcx>( compiler: &'tcx Compiler, crate_types: Vec<CrateType>, stable_crate_id: StableCrateId, - lint_store: Lrc<LintStore>, dep_graph: DepGraph, untracked: Untracked, gcx_cell: &'tcx OnceLock<GlobalCtxt<'tcx>>, @@ -676,7 +664,6 @@ pub fn create_global_ctxt<'tcx>( sess, crate_types, stable_crate_id, - lint_store, arena, hir_arena, untracked, diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 3a5f788e8dd..ace5ec732fb 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -148,8 +148,6 @@ impl<'tcx> Queries<'tcx> { ); let dep_graph = setup_dep_graph(sess, crate_name, stable_crate_id)?; - let lint_store = - Lrc::new(passes::create_lint_store(sess, self.compiler.register_lints.as_deref())); let cstore = FreezeLock::new(Box::new(CStore::new( self.codegen_backend().metadata_loader(), stable_crate_id, @@ -164,7 +162,6 @@ impl<'tcx> Queries<'tcx> { self.compiler, crate_types, stable_crate_id, - lint_store, dep_graph, untracked, &self.gcx_cell, |
