Skip to content

Commit

Permalink
save-analysis: Deduplicate lookup_{d,r}ef_id functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Sep 14, 2019
1 parent 0fafd61 commit 30e39e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
self.save_ctxt.span_from_span(span)
}

fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
self.save_ctxt.lookup_def_id(ref_id)
}

pub fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) {
let source_file = self.tcx.sess.local_crate_source_file.as_ref();
let crate_root = source_file.map(|source_file| {
Expand Down Expand Up @@ -223,13 +227,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
}
}

fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
match self.save_ctxt.get_path_res(ref_id) {
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None,
def => Some(def.def_id()),
}
}

fn process_formals(&mut self, formals: &'l [ast::Param], qualname: &str) {
for arg in formals {
self.visit_pat(&arg.pat);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
let impl_id = self.next_impl_id();
let span = self.span_from_span(sub_span);

let type_data = self.lookup_ref_id(typ.id);
let type_data = self.lookup_def_id(typ.id);
type_data.map(|type_data| {
Data::RelationData(Relation {
kind: RelationKind::Impl {
Expand All @@ -322,7 +322,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
from: id_from_def_id(type_data),
to: trait_ref
.as_ref()
.and_then(|t| self.lookup_ref_id(t.ref_id))
.and_then(|t| self.lookup_def_id(t.ref_id))
.map(id_from_def_id)
.unwrap_or_else(|| null_id()),
},
Expand Down Expand Up @@ -495,7 +495,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
}

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

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

0 comments on commit 30e39e8

Please sign in to comment.