diff options
Diffstat (limited to 'compiler/rustc_resolve/src/lib.rs')
-rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 309 |
1 files changed, 105 insertions, 204 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 1b181b714..1fdfb1a53 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -21,34 +21,34 @@ #[macro_use] extern crate tracing; -pub use rustc_hir::def::{Namespace, PerNS}; - use rustc_arena::{DroplessArena, TypedArena}; use rustc_ast::node_id::NodeMap; use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID}; use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; -use rustc_data_structures::sync::{Lrc, RwLock}; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed}; +use rustc_data_structures::sync::{Lrc, MappedReadGuard}; +use rustc_errors::{ + Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, SubdiagnosticMessage, +}; use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind}; -use rustc_hir::def::Namespace::*; -use rustc_hir::def::{self, CtorOf, DefKind, LifetimeRes, PartialRes}; +use rustc_hir::def::Namespace::{self, *}; +use rustc_hir::def::{self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, PartialRes, PerNS}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId}; use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE}; -use rustc_hir::definitions::{DefPathData, Definitions}; +use rustc_hir::definitions::DefPathData; use rustc_hir::TraitCandidate; use rustc_index::vec::IndexVec; +use rustc_macros::fluent_messages; use rustc_metadata::creader::{CStore, CrateLoader}; use rustc_middle::metadata::ModChild; use rustc_middle::middle::privacy::EffectiveVisibilities; use rustc_middle::span_bug; -use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools}; +use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, TyCtxt}; use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs}; use rustc_query_system::ich::StableHashingContext; -use rustc_session::cstore::{CrateStore, MetadataLoaderDyn, Untracked}; +use rustc_session::cstore::CrateStore; use rustc_session::lint::LintBuffer; -use rustc_session::Session; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident, Symbol}; @@ -60,7 +60,7 @@ use std::collections::BTreeSet; use std::{fmt, ptr}; use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion}; -use imports::{Import, ImportKind, ImportResolver, NameResolution}; +use imports::{Import, ImportKind, NameResolution}; use late::{HasGenericParams, PathSource, PatternSource}; use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef}; @@ -78,6 +78,9 @@ mod ident; mod imports; mod late; mod macros; +pub mod rustdoc; + +fluent_messages! { "../locales/en-US.ftl" } enum Weak { Yes, @@ -85,7 +88,7 @@ enum Weak { } #[derive(Copy, Clone, PartialEq, Debug)] -pub enum Determinacy { +enum Determinacy { Determined, Undetermined, } @@ -138,17 +141,17 @@ enum ScopeSet<'a> { /// This struct is currently used only for early resolution (imports and macros), /// but not for late resolution yet. #[derive(Clone, Copy, Debug)] -pub struct ParentScope<'a> { - pub module: Module<'a>, +struct ParentScope<'a> { + module: Module<'a>, expansion: LocalExpnId, - pub macro_rules: MacroRulesScopeRef<'a>, + macro_rules: MacroRulesScopeRef<'a>, derives: &'a [ast::Path], } impl<'a> ParentScope<'a> { /// Creates a parent scope with the passed argument used as the module scope component, /// and other scope components set to default empty values. - pub fn module(module: Module<'a>, resolver: &Resolver<'a>) -> ParentScope<'a> { + fn module(module: Module<'a>, resolver: &Resolver<'a, '_>) -> ParentScope<'a> { ParentScope { module, expansion: LocalExpnId::ROOT, @@ -256,7 +259,7 @@ enum VisResolutionError<'a> { /// A minimal representation of a path segment. We use this in resolve because we synthesize 'path /// segments' which don't have the rest of an AST or HIR `PathSegment`. #[derive(Clone, Copy, Debug)] -pub struct Segment { +struct Segment { ident: Ident, id: Option<NodeId>, /// Signals whether this `PathSegment` has generic arguments. Used to avoid providing @@ -379,7 +382,7 @@ impl ModuleOrUniformRoot<'_> { } } -#[derive(Clone, Debug)] +#[derive(Debug)] enum PathResult<'a> { Module(ModuleOrUniformRoot<'a>), NonModule(PartialRes), @@ -434,7 +437,7 @@ enum ModuleKind { impl ModuleKind { /// Get name of the module. - pub fn name(&self) -> Option<Symbol> { + fn name(&self) -> Option<Symbol> { match self { ModuleKind::Block => None, ModuleKind::Def(.., name) => Some(*name), @@ -470,7 +473,7 @@ type Resolutions<'a> = RefCell<FxIndexMap<BindingKey, &'a RefCell<NameResolution /// * curly-braced block with statements /// /// You can use [`ModuleData::kind`] to determine the kind of module this is. -pub struct ModuleData<'a> { +struct ModuleData<'a> { /// The direct parent module (it may not be a `mod`, however). parent: Option<Module<'a>>, /// What kind of module this is, because this may not be a `mod`. @@ -529,9 +532,9 @@ impl<'a> ModuleData<'a> { } } - fn for_each_child<R, F>(&'a self, resolver: &mut R, mut f: F) + fn for_each_child<'tcx, R, F>(&'a self, resolver: &mut R, mut f: F) where - R: AsMut<Resolver<'a>>, + R: AsMut<Resolver<'a, 'tcx>>, F: FnMut(&mut R, Ident, Namespace, &'a NameBinding<'a>), { for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() { @@ -542,9 +545,9 @@ impl<'a> ModuleData<'a> { } /// This modifies `self` in place. The traits will be stored in `self.traits`. - fn ensure_traits<R>(&'a self, resolver: &mut R) + fn ensure_traits<'tcx, R>(&'a self, resolver: &mut R) where - R: AsMut<Resolver<'a>>, + R: AsMut<Resolver<'a, 'tcx>>, { let mut traits = self.traits.borrow_mut(); if traits.is_none() { @@ -569,7 +572,7 @@ impl<'a> ModuleData<'a> { } // Public for rustdoc. - pub fn def_id(&self) -> DefId { + fn def_id(&self) -> DefId { self.opt_def_id().expect("`ModuleData::def_id` is called on a block module") } @@ -627,7 +630,7 @@ impl<'a> fmt::Debug for ModuleData<'a> { /// Records a possibly-private value, type, or module definition. #[derive(Clone, Debug)] -pub struct NameBinding<'a> { +struct NameBinding<'a> { kind: NameBindingKind<'a>, ambiguity: Option<(&'a NameBinding<'a>, AmbiguityKind)>, expansion: LocalExpnId, @@ -635,7 +638,7 @@ pub struct NameBinding<'a> { vis: ty::Visibility<DefId>, } -pub trait ToNameBinding<'a> { +trait ToNameBinding<'a> { fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a>; } @@ -839,9 +842,9 @@ impl<'a> NameBinding<'a> { } #[derive(Default, Clone)] -pub struct ExternPreludeEntry<'a> { +struct ExternPreludeEntry<'a> { extern_crate_item: Option<&'a NameBinding<'a>>, - pub introduced_by_item: bool, + introduced_by_item: bool, } /// Used for better errors for E0773 @@ -865,8 +868,8 @@ struct MacroData { /// The main resolver class. /// /// This is the visitor that walks the whole crate. -pub struct Resolver<'a> { - session: &'a Session, +pub struct Resolver<'a, 'tcx> { + tcx: TyCtxt<'tcx>, /// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`. expn_that_defined: FxHashMap<LocalDefId, ExpnId>, @@ -943,23 +946,19 @@ pub struct Resolver<'a> { has_pub_restricted: bool, used_imports: FxHashSet<NodeId>, maybe_unused_trait_imports: FxIndexSet<LocalDefId>, - maybe_unused_extern_crates: Vec<(LocalDefId, Span)>, /// Privacy errors are delayed until the end in order to deduplicate them. privacy_errors: Vec<PrivacyError<'a>>, /// Ambiguity errors are delayed for deduplication. ambiguity_errors: Vec<AmbiguityError<'a>>, /// `use` injections are delayed for better placement and deduplication. - use_injections: Vec<UseError<'a>>, + use_injections: Vec<UseError<'tcx>>, /// Crate-local macro expanded `macro_export` referred to by a module-relative path. macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>, arenas: &'a ResolverArenas<'a>, dummy_binding: &'a NameBinding<'a>, - local_crate_name: Symbol, - metadata_loader: Box<MetadataLoaderDyn>, - untracked: Untracked, used_extern_options: FxHashSet<Symbol>, macro_names: FxHashSet<Ident>, builtin_macros: FxHashMap<Symbol, BuiltinMacroState>, @@ -1046,6 +1045,9 @@ pub struct Resolver<'a> { lifetime_elision_allowed: FxHashSet<NodeId>, effective_visibilities: EffectiveVisibilities, + doc_link_resolutions: FxHashMap<LocalDefId, DocLinkResMap>, + doc_link_traits_in_scope: FxHashMap<LocalDefId, Vec<DefId>>, + all_macro_rules: FxHashMap<Symbol, Res>, } /// Nothing really interesting here; it just provides memory for the rest of the crate. @@ -1109,42 +1111,25 @@ impl<'a> ResolverArenas<'a> { } } -impl<'a> AsMut<Resolver<'a>> for Resolver<'a> { - fn as_mut(&mut self) -> &mut Resolver<'a> { +impl<'a, 'tcx> AsMut<Resolver<'a, 'tcx>> for Resolver<'a, 'tcx> { + fn as_mut(&mut self) -> &mut Resolver<'a, 'tcx> { self } } -/// A minimal subset of resolver that can implemenent `DefIdTree`, sometimes -/// required to satisfy borrow checker by avoiding borrowing the whole resolver. -#[derive(Clone, Copy)] -struct ResolverTree<'a>(&'a Untracked); - -impl DefIdTree for ResolverTree<'_> { - #[inline] - fn opt_parent(self, id: DefId) -> Option<DefId> { - let ResolverTree(Untracked { definitions, cstore, .. }) = self; - match id.as_local() { - Some(id) => definitions.read().def_key(id).parent, - None => cstore.as_any().downcast_ref::<CStore>().unwrap().def_key(id).parent, - } - .map(|index| DefId { index, ..id }) - } -} - -impl<'a, 'b> DefIdTree for &'a Resolver<'b> { +impl<'a, 'b, 'tcx> DefIdTree for &'a Resolver<'b, 'tcx> { #[inline] fn opt_parent(self, id: DefId) -> Option<DefId> { - ResolverTree(&self.untracked).opt_parent(id) + self.tcx.opt_parent(id) } } -impl<'a> Resolver<'a> { +impl<'tcx> Resolver<'_, 'tcx> { fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> { self.node_id_to_def_id.get(&node).copied() } - pub fn local_def_id(&self, node: NodeId) -> LocalDefId { + fn local_def_id(&self, node: NodeId) -> LocalDefId { self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node)) } @@ -1162,10 +1147,11 @@ impl<'a> Resolver<'a> { "adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}", node_id, data, - self.untracked.definitions.read().def_key(self.node_id_to_def_id[&node_id]), + self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id]), ); - let def_id = self.untracked.definitions.write().create_def(parent, data); + // FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()` + let def_id = self.tcx.untracked().definitions.write().create_def(parent, data); // Create the definition. if expn_id != ExpnId::root() { @@ -1174,7 +1160,7 @@ impl<'a> Resolver<'a> { // A relative span's parent must be an absolute span. debug_assert_eq!(span.data_untracked().parent, None); - let _id = self.untracked.source_span.push(span); + let _id = self.tcx.untracked().source_span.push(span); debug_assert_eq!(_id, def_id); // Some things for which we allocate `LocalDefId`s don't correspond to @@ -1193,23 +1179,21 @@ impl<'a> Resolver<'a> { if let Some(def_id) = def_id.as_local() { self.item_generics_num_lifetimes[&def_id] } else { - self.cstore().item_generics_num_lifetimes(def_id, self.session) + self.cstore().item_generics_num_lifetimes(def_id, self.tcx.sess) } } - pub fn sess(&self) -> &'a Session { - self.session + pub fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx } } -impl<'a> Resolver<'a> { +impl<'a, 'tcx> Resolver<'a, 'tcx> { pub fn new( - session: &'a Session, + tcx: TyCtxt<'tcx>, krate: &Crate, - crate_name: Symbol, - metadata_loader: Box<MetadataLoaderDyn>, arenas: &'a ResolverArenas<'a>, - ) -> Resolver<'a> { + ) -> Resolver<'a, 'tcx> { let root_def_id = CRATE_DEF_ID.to_def_id(); let mut module_map = FxHashMap::default(); let graph_root = arenas.new_module( @@ -1217,7 +1201,7 @@ impl<'a> Resolver<'a> { ModuleKind::Def(DefKind::Mod, root_def_id, kw::Empty), ExpnId::root(), krate.spans.inner_span, - session.contains_name(&krate.attrs, sym::no_implicit_prelude), + tcx.sess.contains_name(&krate.attrs, sym::no_implicit_prelude), &mut module_map, ); let empty_module = arenas.new_module( @@ -1229,8 +1213,6 @@ impl<'a> Resolver<'a> { &mut FxHashMap::default(), ); - let definitions = Definitions::new(session.local_stable_crate_id()); - let mut visibilities = FxHashMap::default(); visibilities.insert(CRATE_DEF_ID, ty::Visibility::Public); @@ -1242,11 +1224,8 @@ impl<'a> Resolver<'a> { let mut invocation_parents = FxHashMap::default(); invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential)); - let mut source_span = IndexVec::default(); - let _id = source_span.push(krate.spans.inner_span); - debug_assert_eq!(_id, CRATE_DEF_ID); - - let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = session + let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = tcx + .sess .opts .externs .iter() @@ -1254,19 +1233,19 @@ impl<'a> Resolver<'a> { .map(|(name, _)| (Ident::from_str(name), Default::default())) .collect(); - if !session.contains_name(&krate.attrs, sym::no_core) { + if !tcx.sess.contains_name(&krate.attrs, sym::no_core) { extern_prelude.insert(Ident::with_dummy_span(sym::core), Default::default()); - if !session.contains_name(&krate.attrs, sym::no_std) { + if !tcx.sess.contains_name(&krate.attrs, sym::no_std) { extern_prelude.insert(Ident::with_dummy_span(sym::std), Default::default()); } } - let registered_tools = macros::registered_tools(session, &krate.attrs); + let registered_tools = macros::registered_tools(tcx.sess, &krate.attrs); - let features = session.features_untracked(); + let features = tcx.sess.features_untracked(); let mut resolver = Resolver { - session, + tcx, expn_that_defined: Default::default(), @@ -1304,7 +1283,6 @@ impl<'a> Resolver<'a> { has_pub_restricted: false, used_imports: FxHashSet::default(), maybe_unused_trait_imports: Default::default(), - maybe_unused_extern_crates: Vec::new(), privacy_errors: Vec::new(), ambiguity_errors: Vec::new(), @@ -1320,23 +1298,16 @@ impl<'a> Resolver<'a> { vis: ty::Visibility::Public, }), - metadata_loader, - local_crate_name: crate_name, used_extern_options: Default::default(), - untracked: Untracked { - cstore: Box::new(CStore::new(session)), - source_span, - definitions: RwLock::new(definitions), - }, macro_names: FxHashSet::default(), builtin_macros: Default::default(), builtin_macro_kinds: Default::default(), registered_tools, macro_use_prelude: FxHashMap::default(), macro_map: FxHashMap::default(), - dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(session.edition())), - dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(session.edition())), - non_macro_attr: Lrc::new(SyntaxExtension::non_macro_attr(session.edition())), + dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(tcx.sess.edition())), + dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(tcx.sess.edition())), + non_macro_attr: Lrc::new(SyntaxExtension::non_macro_attr(tcx.sess.edition())), invocation_parent_scopes: Default::default(), output_macro_rules_scopes: Default::default(), macro_rules_scopes: Default::default(), @@ -1374,6 +1345,9 @@ impl<'a> Resolver<'a> { confused_type_with_std_module: Default::default(), lifetime_elision_allowed: Default::default(), effective_visibilities: Default::default(), + doc_link_resolutions: Default::default(), + doc_link_traits_in_scope: Default::default(), + all_macro_rules: Default::default(), }; let root_parent_scope = ParentScope::module(graph_root, &resolver); @@ -1394,14 +1368,14 @@ impl<'a> Resolver<'a> { self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude, module_map) } - pub fn next_node_id(&mut self) -> NodeId { + fn next_node_id(&mut self) -> NodeId { let start = self.next_node_id; let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds"); self.next_node_id = ast::NodeId::from_u32(next); start } - pub fn next_node_ids(&mut self, count: usize) -> std::ops::Range<NodeId> { + fn next_node_ids(&mut self, count: usize) -> std::ops::Range<NodeId> { let start = self.next_node_id; let end = start.as_usize().checked_add(count).expect("input too large; ran out of NodeIds"); self.next_node_id = ast::NodeId::from_usize(end); @@ -1424,12 +1398,10 @@ impl<'a> Resolver<'a> { let extern_crate_map = self.extern_crate_map; let reexport_map = self.reexport_map; let maybe_unused_trait_imports = self.maybe_unused_trait_imports; - let maybe_unused_extern_crates = self.maybe_unused_extern_crates; let glob_map = self.glob_map; let main_def = self.main_def; let confused_type_with_std_module = self.confused_type_with_std_module; let effective_visibilities = self.effective_visibilities; - let untracked = self.untracked; let global_ctxt = ResolverGlobalCtxt { expn_that_defined, visibilities, @@ -1439,17 +1411,14 @@ impl<'a> Resolver<'a> { reexport_map, glob_map, maybe_unused_trait_imports, - maybe_unused_extern_crates, - extern_prelude: self - .extern_prelude - .iter() - .map(|(ident, entry)| (ident.name, entry.introduced_by_item)) - .collect(), main_def, trait_impls: self.trait_impls, proc_macros, confused_type_with_std_module, registered_tools: self.registered_tools, + doc_link_resolutions: self.doc_link_resolutions, + doc_link_traits_in_scope: self.doc_link_traits_in_scope, + all_macro_rules: self.all_macro_rules, }; let ast_lowering = ty::ResolverAstLowering { legacy_const_generic_args: self.legacy_const_generic_args, @@ -1465,70 +1434,21 @@ impl<'a> Resolver<'a> { builtin_macro_kinds: self.builtin_macro_kinds, lifetime_elision_allowed: self.lifetime_elision_allowed, }; - ResolverOutputs { global_ctxt, ast_lowering, untracked } - } - - pub fn clone_outputs(&self) -> ResolverOutputs { - let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect(); - let definitions = self.untracked.definitions.clone(); - let cstore = Box::new(self.cstore().clone()); - let untracked = - Untracked { cstore, source_span: self.untracked.source_span.clone(), definitions }; - let global_ctxt = ResolverGlobalCtxt { - expn_that_defined: self.expn_that_defined.clone(), - visibilities: self.visibilities.clone(), - has_pub_restricted: self.has_pub_restricted, - extern_crate_map: self.extern_crate_map.clone(), - reexport_map: self.reexport_map.clone(), - glob_map: self.glob_map.clone(), - maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(), - maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(), - extern_prelude: self - .extern_prelude - .iter() - .map(|(ident, entry)| (ident.name, entry.introduced_by_item)) - .collect(), - main_def: self.main_def, - trait_impls: self.trait_impls.clone(), - proc_macros, - confused_type_with_std_module: self.confused_type_with_std_module.clone(), - registered_tools: self.registered_tools.clone(), - effective_visibilities: self.effective_visibilities.clone(), - }; - let ast_lowering = ty::ResolverAstLowering { - legacy_const_generic_args: self.legacy_const_generic_args.clone(), - partial_res_map: self.partial_res_map.clone(), - import_res_map: self.import_res_map.clone(), - label_res_map: self.label_res_map.clone(), - lifetimes_res_map: self.lifetimes_res_map.clone(), - extra_lifetime_params_map: self.extra_lifetime_params_map.clone(), - next_node_id: self.next_node_id, - node_id_to_def_id: self.node_id_to_def_id.clone(), - def_id_to_node_id: self.def_id_to_node_id.clone(), - trait_map: self.trait_map.clone(), - builtin_macro_kinds: self.builtin_macro_kinds.clone(), - lifetime_elision_allowed: self.lifetime_elision_allowed.clone(), - }; - ResolverOutputs { global_ctxt, ast_lowering, untracked } + ResolverOutputs { global_ctxt, ast_lowering } } fn create_stable_hashing_context(&self) -> StableHashingContext<'_> { - StableHashingContext::new(self.session, &self.untracked) + StableHashingContext::new(self.tcx.sess, self.tcx.untracked()) } - pub fn crate_loader(&mut self) -> CrateLoader<'_> { - CrateLoader::new( - &self.session, - &*self.metadata_loader, - self.local_crate_name, - &mut *self.untracked.cstore.untracked_as_any().downcast_mut().unwrap(), - self.untracked.definitions.read(), - &mut self.used_extern_options, - ) + fn crate_loader<T>(&mut self, f: impl FnOnce(&mut CrateLoader<'_, '_>) -> T) -> T { + let mut cstore = self.tcx.untracked().cstore.write(); + let cstore = cstore.untracked_as_any().downcast_mut().unwrap(); + f(&mut CrateLoader::new(self.tcx, &mut *cstore, &mut self.used_extern_options)) } - pub fn cstore(&self) -> &CStore { - self.untracked.cstore.as_any().downcast_ref().unwrap() + fn cstore(&self) -> MappedReadGuard<'_, CStore> { + CStore::from_tcx(self.tcx) } fn dummy_ext(&self, macro_kind: MacroKind) -> Lrc<SyntaxExtension> { @@ -1561,21 +1481,26 @@ impl<'a> Resolver<'a> { /// Entry point to crate resolution. pub fn resolve_crate(&mut self, krate: &Crate) { - self.session.time("resolve_crate", || { - self.session.time("finalize_imports", || ImportResolver { r: self }.finalize_imports()); - self.session.time("compute_effective_visibilities", || { + self.tcx.sess.time("resolve_crate", || { + self.tcx.sess.time("finalize_imports", || self.finalize_imports()); + self.tcx.sess.time("compute_effective_visibilities", || { EffectiveVisibilitiesVisitor::compute_effective_visibilities(self, krate) }); - self.session.time("finalize_macro_resolutions", || self.finalize_macro_resolutions()); - self.session.time("late_resolve_crate", || self.late_resolve_crate(krate)); - self.session.time("resolve_main", || self.resolve_main()); - self.session.time("resolve_check_unused", || self.check_unused(krate)); - self.session.time("resolve_report_errors", || self.report_errors(krate)); - self.session.time("resolve_postprocess", || self.crate_loader().postprocess(krate)); + self.tcx.sess.time("finalize_macro_resolutions", || self.finalize_macro_resolutions()); + self.tcx.sess.time("late_resolve_crate", || self.late_resolve_crate(krate)); + self.tcx.sess.time("resolve_main", || self.resolve_main()); + self.tcx.sess.time("resolve_check_unused", || self.check_unused(krate)); + self.tcx.sess.time("resolve_report_errors", || self.report_errors(krate)); + self.tcx + .sess + .time("resolve_postprocess", || self.crate_loader(|c| c.postprocess(krate))); }); + + // Make sure we don't mutate the cstore from here on. + self.tcx.untracked().cstore.leak(); } - pub fn traits_in_scope( + fn traits_in_scope( &mut self, current_trait: Option<Module<'a>>, parent_scope: &ParentScope<'a>, @@ -1911,10 +1836,10 @@ impl<'a> Resolver<'a> { } else { let crate_id = if finalize { let Some(crate_id) = - self.crate_loader().process_path_extern(ident.name, ident.span) else { return Some(self.dummy_binding); }; + self.crate_loader(|c| c.process_path_extern(ident.name, ident.span)) else { return Some(self.dummy_binding); }; crate_id } else { - self.crate_loader().maybe_process_path_extern(ident.name)? + self.crate_loader(|c| c.maybe_process_path_extern(ident.name))? }; let crate_root = self.expect_module(crate_id.as_def_id()); let vis = ty::Visibility::<LocalDefId>::Public; @@ -1927,7 +1852,7 @@ impl<'a> Resolver<'a> { /// isn't something that can be returned because it can't be made to live that long, /// and also it's a private type. Fortunately rustdoc doesn't need to know the error, /// just that an error occurred. - pub fn resolve_rustdoc_path( + fn resolve_rustdoc_path( &mut self, path_str: &str, ns: Namespace, @@ -1959,41 +1884,17 @@ impl<'a> Resolver<'a> { } } - /// For rustdoc. - /// For local modules returns only reexports, for external modules returns all children. - pub fn module_children_or_reexports(&self, def_id: DefId) -> Vec<ModChild> { - if let Some(def_id) = def_id.as_local() { - self.reexport_map.get(&def_id).cloned().unwrap_or_default() - } else { - self.cstore().module_children_untracked(def_id, self.session).collect() - } - } - - /// For rustdoc. - pub fn macro_rules_scope(&self, def_id: LocalDefId) -> (MacroRulesScopeRef<'a>, Res) { - let scope = *self.macro_rules_scopes.get(&def_id).expect("not a `macro_rules` item"); - match scope.get() { - MacroRulesScope::Binding(mb) => (scope, mb.binding.res()), - _ => unreachable!(), - } - } - - /// For rustdoc. - pub fn get_partial_res(&self, node_id: NodeId) -> Option<PartialRes> { - self.partial_res_map.get(&node_id).copied() - } - /// Retrieves the span of the given `DefId` if `DefId` is in the local crate. #[inline] - pub fn opt_span(&self, def_id: DefId) -> Option<Span> { - def_id.as_local().map(|def_id| self.untracked.source_span[def_id]) + fn opt_span(&self, def_id: DefId) -> Option<Span> { + def_id.as_local().map(|def_id| self.tcx.source_span(def_id)) } /// Retrieves the name of the given `DefId`. #[inline] - pub fn opt_name(&self, def_id: DefId) -> Option<Symbol> { + fn opt_name(&self, def_id: DefId) -> Option<Symbol> { let def_key = match def_id.as_local() { - Some(def_id) => self.untracked.definitions.read().def_key(def_id), + Some(def_id) => self.tcx.definitions_untracked().def_key(def_id), None => self.cstore().def_key(def_id), }; def_key.get_opt_name() @@ -2002,7 +1903,7 @@ impl<'a> Resolver<'a> { /// Checks if an expression refers to a function marked with /// `#[rustc_legacy_const_generics]` and returns the argument index list /// from the attribute. - pub fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>> { + fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>> { if let ExprKind::Path(None, path) = &expr.kind { // Don't perform legacy const generics rewriting if the path already // has generic arguments. @@ -2025,7 +1926,7 @@ impl<'a> Resolver<'a> { let attr = self .cstore() - .item_attrs_untracked(def_id, self.session) + .item_attrs_untracked(def_id, self.tcx.sess) .find(|a| a.has_name(sym::rustc_legacy_const_generics))?; let mut ret = Vec::new(); for meta in attr.meta_item_list()? { |