diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 2438c061475e5..06a64f0db0e32 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1041,13 +1041,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { self.root.tables.optimized_mir.get(self, id).is_some() } - fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId { - match self.def_kind(id) { - DefKind::Mod | DefKind::Enum | DefKind::Trait => self.get_expn_that_defined(id, sess), - _ => panic!("Expected module, found {:?}", self.local_def_id(id)), - } - } - fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool { self.root .tables diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 3182c6c08873e..8a0e43a565980 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -501,14 +501,6 @@ impl CStore { self.get_crate_data(def.krate).get_ctor(def.index) } - pub fn module_children_untracked<'a>( - &'a self, - def_id: DefId, - sess: &'a Session, - ) -> impl Iterator + 'a { - self.get_crate_data(def_id.krate).get_module_children(def_id.index, sess) - } - pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro { let _prof_timer = sess.prof.generic_activity("metadata_load_macro"); @@ -537,18 +529,6 @@ impl CStore { ) } - pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span { - self.get_crate_data(def_id.krate).get_span(def_id.index, sess) - } - - pub fn def_kind(&self, def: DefId) -> DefKind { - self.get_crate_data(def.krate).def_kind(def.index) - } - - pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId { - self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess) - } - /// Only public-facing way to traverse all the definitions in a non-local crate. /// Critically useful for this third-party project: . /// See for context. diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index f031d7cdb1aa3..2a7955b709800 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -24,7 +24,7 @@ use rustc_errors::{struct_span_err, Applicability}; use rustc_expand::expand::AstFragment; use rustc_hir::def::{self, *}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; -use rustc_metadata::creader::LoadedMacro; +use rustc_metadata::creader::{CStore, LoadedMacro}; use rustc_middle::metadata::ModChild; use rustc_middle::{bug, ty}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind}; @@ -114,17 +114,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } if !def_id.is_local() { - let def_kind = self.cstore().def_kind(def_id); + let def_kind = self.tcx.def_kind(def_id); if let DefKind::Mod | DefKind::Enum | DefKind::Trait = def_kind { let parent = self .tcx .opt_parent(def_id) .map(|parent_id| self.get_nearest_non_block_module(parent_id)); - let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess); return Some(self.new_module( parent, ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)), - expn_id, + self.tcx.expn_that_defined(def_id), self.def_span(def_id), // FIXME: Account for `#[no_implicit_prelude]` attributes. parent.map_or(false, |module| module.no_implicit_prelude), @@ -168,7 +167,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { return macro_data.clone(); } - let load_macro_untracked = self.cstore().load_macro_untracked(def_id, &self.tcx.sess); + let load_macro_untracked = + CStore::from_tcx(self.tcx).load_macro_untracked(def_id, &self.tcx.sess); let (ext, macro_rules) = match load_macro_untracked { LoadedMacro::MacroDef(item, edition) => ( Lrc::new(self.compile_macro(&item, edition).0), @@ -194,9 +194,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) { - let children = - Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.tcx.sess)); - for child in children { + for &child in self.tcx.module_children(module.def_id()) { let parent_scope = ParentScope::module(module, self); BuildReducedGraphVisitor { r: self, parent_scope } .build_reduced_graph_for_external_crate_res(child); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index df7681dc4267b..d51afe2c78321 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -21,6 +21,7 @@ use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind}; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_hir::PrimTy; +use rustc_metadata::creader::CStore; use rustc_session::lint; use rustc_session::parse::feature_err; use rustc_session::Session; @@ -1419,7 +1420,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> { let struct_ctor = match def_id.as_local() { Some(def_id) => self.r.struct_constructors.get(&def_id).cloned(), None => { - let ctor = self.r.cstore().ctor_untracked(def_id); + let ctor = CStore::from_tcx(self.r.tcx).ctor_untracked(def_id); ctor.map(|(ctor_kind, ctor_def_id)| { let ctor_res = Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 0a99295b59a73..cfa91b7e291ac 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -28,7 +28,7 @@ use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArg use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; use rustc_data_structures::steal::Steal; -use rustc_data_structures::sync::{Lrc, MappedReadGuard}; +use rustc_data_structures::sync::Lrc; use rustc_errors::{ Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, SubdiagnosticMessage, }; @@ -1438,10 +1438,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { )) } - fn cstore(&self) -> MappedReadGuard<'_, CStore> { - CStore::from_tcx(self.tcx) - } - fn dummy_ext(&self, macro_kind: MacroKind) -> Lrc { match macro_kind { MacroKind::Bang => self.dummy_ext_bang.clone(), @@ -1871,7 +1867,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { fn def_span(&self, def_id: DefId) -> Span { match def_id.as_local() { Some(def_id) => self.tcx.source_span(def_id), - None => self.cstore().get_span_untracked(def_id, self.tcx.sess), + None => self.tcx.def_span(def_id), } } diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index c540682d8db38..0fec8666c3889 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -17,6 +17,7 @@ use rustc_expand::compile_declarative_macro; use rustc_expand::expand::{AstFragment, Invocation, InvocationKind, SupportsMacroExpansion}; use rustc_hir::def::{self, DefKind, NonMacroAttrKind}; use rustc_hir::def_id::{CrateNum, LocalDefId}; +use rustc_metadata::creader::CStore; use rustc_middle::middle::stability; use rustc_middle::ty::RegisteredTools; use rustc_middle::ty::TyCtxt; @@ -459,7 +460,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> { } fn get_proc_macro_quoted_span(&self, krate: CrateNum, id: usize) -> Span { - self.cstore().get_proc_macro_quoted_span_untracked(krate, id, self.tcx.sess) + CStore::from_tcx(self.tcx).get_proc_macro_quoted_span_untracked(krate, id, self.tcx.sess) } fn declare_proc_macro(&mut self, id: NodeId) {