Skip to content

Commit 7472f9e

Browse files
committed
lowering: remove dep on CrateStore
1 parent 402907f commit 7472f9e

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

src/librustc_ast_lowering/lib.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
3939
use rustc::hir::map::Map;
4040
use rustc::lint;
4141
use rustc::lint::builtin;
42-
use rustc::middle::cstore::CrateStore;
4342
use rustc::{bug, span_bug};
4443
use rustc_data_structures::captures::Captures;
4544
use rustc_data_structures::fx::FxHashSet;
@@ -172,7 +171,9 @@ struct LoweringContext<'a, 'hir: 'a> {
172171
}
173172

174173
pub trait Resolver {
175-
fn cstore(&self) -> &dyn CrateStore;
174+
fn def_key(&mut self, id: DefId) -> DefKey;
175+
176+
fn item_generics_cloned_untracked_liftimes(&self, def: DefId, sess: &Session) -> usize;
176177

177178
/// Obtains resolution for a `NodeId` with a single resolution.
178179
fn get_partial_res(&mut self, id: NodeId) -> Option<PartialRes>;
@@ -936,14 +937,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
936937
ret
937938
}
938939

939-
fn def_key(&mut self, id: DefId) -> DefKey {
940-
if id.is_local() {
941-
self.resolver.definitions().def_key(id.index)
942-
} else {
943-
self.resolver.cstore().def_key(id)
944-
}
945-
}
946-
947940
fn lower_attrs(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
948941
self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a)))
949942
}

src/librustc_ast_lowering/path.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4949
// which may need lifetime elision performed.
5050
let parent_def_id = |this: &mut Self, def_id: DefId| DefId {
5151
krate: def_id.krate,
52-
index: this.def_key(def_id).parent.expect("missing parent"),
52+
index: this.resolver.def_key(def_id).parent.expect("missing parent"),
5353
};
5454
let type_def_id = match partial_res.base_res() {
5555
Res::Def(DefKind::AssocTy, def_id) if i + 2 == proj_start => {
@@ -93,11 +93,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
9393
return n;
9494
}
9595
assert!(!def_id.is_local());
96-
let item_generics = self
96+
let n = self
9797
.resolver
98-
.cstore()
99-
.item_generics_cloned_untracked(def_id, self.sess);
100-
let n = item_generics.own_counts().lifetimes;
98+
.item_generics_cloned_untracked_liftimes(def_id, self.sess);
10199
self.type_def_lifetime_params.insert(def_id, n);
102100
n
103101
});

src/librustc_resolve/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Determinacy::*;
2222

2323
use errors::{struct_span_err, Applicability, DiagnosticBuilder};
2424
use rustc::hir::exports::ExportMap;
25-
use rustc::hir::map::Definitions;
25+
use rustc::hir::map::{DefKey, Definitions};
2626
use rustc::lint;
2727
use rustc::middle::cstore::{CrateStore, MetadataLoaderDyn};
2828
use rustc::session::Session;
@@ -1027,8 +1027,12 @@ impl<'a, 'b> DefIdTree for &'a Resolver<'b> {
10271027
/// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that
10281028
/// the resolver is no longer needed as all the relevant information is inline.
10291029
impl rustc_ast_lowering::Resolver for Resolver<'_> {
1030-
fn cstore(&self) -> &dyn CrateStore {
1031-
self.cstore()
1030+
fn def_key(&mut self, id: DefId) -> DefKey {
1031+
if id.is_local() { self.definitions().def_key(id.index) } else { self.cstore().def_key(id) }
1032+
}
1033+
1034+
fn item_generics_cloned_untracked_liftimes(&self, def_id: DefId, sess: &Session) -> usize {
1035+
self.cstore().item_generics_cloned_untracked(def_id, sess).own_counts().lifetimes
10321036
}
10331037

10341038
fn resolve_str_path(

0 commit comments

Comments
 (0)