lowering: remove dep on CrateStore

This commit is contained in:
Mazdak Farrokhzad 2020-01-06 07:34:52 +01:00
parent 402907f273
commit 7472f9ef13
3 changed files with 13 additions and 18 deletions

View file

@ -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<PartialRes>;
@ -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)))
}

View file

@ -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
});

View file

@ -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(