From 1cec923fbb9f5a71ff9664e9c8eba9d40ed02319 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 23 Mar 2023 20:44:48 +0400 Subject: [PATCH] rustc_metadata: Freeze cstore after the full crate list is queried --- compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 0d54f292636..3a50d7c9363 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -490,6 +490,9 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { .alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE)) }, crates: |tcx, ()| { + // The list of loaded crates is now frozen in query cache, + // so make sure cstore is not mutably accessed from here on. + tcx.untracked().cstore.leak(); tcx.arena.alloc_from_iter(CStore::from_tcx(tcx).iter_crate_data().map(|(cnum, _)| cnum)) }, ..*providers