From 7472f9ef134465c8d077269236f09e8ef5767772 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 6 Jan 2020 07:34:52 +0100 Subject: [PATCH] lowering: remove dep on CrateStore --- src/librustc_ast_lowering/lib.rs | 13 +++---------- src/librustc_ast_lowering/path.rs | 8 +++----- src/librustc_resolve/lib.rs | 10 +++++++--- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index f5d051618e2d..d2a51c5d9cc2 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -39,7 +39,6 @@ use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions}; use rustc::hir::map::Map; use rustc::lint; use rustc::lint::builtin; -use rustc::middle::cstore::CrateStore; use rustc::{bug, span_bug}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashSet; @@ -172,7 +171,9 @@ struct LoweringContext<'a, 'hir: 'a> { } pub trait Resolver { - fn cstore(&self) -> &dyn CrateStore; + fn def_key(&mut self, id: DefId) -> DefKey; + + fn item_generics_cloned_untracked_liftimes(&self, def: DefId, sess: &Session) -> usize; /// Obtains resolution for a `NodeId` with a single resolution. fn get_partial_res(&mut self, id: NodeId) -> Option; @@ -936,14 +937,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ret } - fn def_key(&mut self, id: DefId) -> DefKey { - if id.is_local() { - self.resolver.definitions().def_key(id.index) - } else { - self.resolver.cstore().def_key(id) - } - } - fn lower_attrs(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] { self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a))) } diff --git a/src/librustc_ast_lowering/path.rs b/src/librustc_ast_lowering/path.rs index 4f71910b0bfe..b4c196a254e4 100644 --- a/src/librustc_ast_lowering/path.rs +++ b/src/librustc_ast_lowering/path.rs @@ -49,7 +49,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // which may need lifetime elision performed. let parent_def_id = |this: &mut Self, def_id: DefId| DefId { krate: def_id.krate, - index: this.def_key(def_id).parent.expect("missing parent"), + index: this.resolver.def_key(def_id).parent.expect("missing parent"), }; let type_def_id = match partial_res.base_res() { Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start => { @@ -93,11 +93,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { return n; } assert!(!def_id.is_local()); - let item_generics = self + let n = self .resolver - .cstore() - .item_generics_cloned_untracked(def_id, self.sess); - let n = item_generics.own_counts().lifetimes; + .item_generics_cloned_untracked_liftimes(def_id, self.sess); self.type_def_lifetime_params.insert(def_id, n); n }); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index f8e42724df72..8a6248aba866 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -22,7 +22,7 @@ use Determinacy::*; use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::exports::ExportMap; -use rustc::hir::map::Definitions; +use rustc::hir::map::{DefKey, Definitions}; use rustc::lint; use rustc::middle::cstore::{CrateStore, MetadataLoaderDyn}; use rustc::session::Session; @@ -1027,8 +1027,12 @@ impl<'a, 'b> DefIdTree for &'a Resolver<'b> { /// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that /// the resolver is no longer needed as all the relevant information is inline. impl rustc_ast_lowering::Resolver for Resolver<'_> { - fn cstore(&self) -> &dyn CrateStore { - self.cstore() + fn def_key(&mut self, id: DefId) -> DefKey { + if id.is_local() { self.definitions().def_key(id.index) } else { self.cstore().def_key(id) } + } + + fn item_generics_cloned_untracked_liftimes(&self, def_id: DefId, sess: &Session) -> usize { + self.cstore().item_generics_cloned_untracked(def_id, sess).own_counts().lifetimes } fn resolve_str_path(