Skip to content

Commit 30e39e8

Browse files
committed
save-analysis: Deduplicate lookup_{d,r}ef_id functions
1 parent 0fafd61 commit 30e39e8

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/librustc_save_analysis/dump_visitor.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
130130
self.save_ctxt.span_from_span(span)
131131
}
132132

133+
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
134+
self.save_ctxt.lookup_def_id(ref_id)
135+
}
136+
133137
pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
134138
let source_file = self.tcx.sess.local_crate_source_file.as_ref();
135139
let crate_root = source_file.map(|source_file| {
@@ -223,13 +227,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
223227
}
224228
}
225229

226-
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
227-
match self.save_ctxt.get_path_res(ref_id) {
228-
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None,
229-
def => Some(def.def_id()),
230-
}
231-
}
232-
233230
fn process_formals(&mut self, formals: &'l [ast::Param], qualname: &str) {
234231
for arg in formals {
235232
self.visit_pat(&arg.pat);

src/librustc_save_analysis/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
312312
let impl_id = self.next_impl_id();
313313
let span = self.span_from_span(sub_span);
314314

315-
let type_data = self.lookup_ref_id(typ.id);
315+
let type_data = self.lookup_def_id(typ.id);
316316
type_data.map(|type_data| {
317317
Data::RelationData(Relation {
318318
kind: RelationKind::Impl {
@@ -322,7 +322,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
322322
from: id_from_def_id(type_data),
323323
to: trait_ref
324324
.as_ref()
325-
.and_then(|t| self.lookup_ref_id(t.ref_id))
325+
.and_then(|t| self.lookup_def_id(t.ref_id))
326326
.map(id_from_def_id)
327327
.unwrap_or_else(|| null_id()),
328328
},
@@ -495,7 +495,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
495495
}
496496

497497
pub fn get_trait_ref_data(&self, trait_ref: &ast::TraitRef) -> Option<Ref> {
498-
self.lookup_ref_id(trait_ref.ref_id).and_then(|def_id| {
498+
self.lookup_def_id(trait_ref.ref_id).and_then(|def_id| {
499499
let span = trait_ref.path.span;
500500
if generated_code(span) {
501501
return None;
@@ -870,7 +870,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
870870
})
871871
}
872872

873-
fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> {
873+
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
874874
match self.get_path_res(ref_id) {
875875
Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None,
876876
def => Some(def.def_id()),

0 commit comments

Comments
 (0)