Skip to content

Commit 49d3a93

Browse files
committed
save-analysis: fix def_ids for method calls
We were sometime emitting the decl as a def.
1 parent 94f13ac commit 49d3a93

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/librustc/ast_map/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ impl<'ast> Map<'ast> {
411411
}
412412
}
413413

414+
pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem {
415+
match self.find(id) {
416+
Some(NodeTraitItem(item)) => item,
417+
_ => panic!("expected trait item, found {}", self.node_to_string(id))
418+
}
419+
}
420+
414421
pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
415422
match self.find(id) {
416423
Some(NodeItem(i)) => {

src/librustc_trans/save/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
548548
let ti = self.tcx.impl_or_trait_item(decl_id);
549549
match provenence {
550550
def::FromTrait(def_id) => {
551-
Some(self.tcx.trait_items(def_id)
552-
.iter()
553-
.find(|mr| {
554-
mr.name() == ti.name()
555-
})
556-
.unwrap()
557-
.def_id())
551+
self.tcx.trait_items(def_id)
552+
.iter()
553+
.find(|mr| {
554+
mr.name() == ti.name() && self.trait_method_has_body(mr)
555+
})
556+
.map(|mr| mr.def_id())
558557
}
559558
def::FromImpl(def_id) => {
560559
let impl_items = self.tcx.impl_items.borrow();
@@ -594,6 +593,20 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
594593
}
595594
}
596595

596+
fn trait_method_has_body(&self, mr: &ty::ImplOrTraitItem) -> bool {
597+
let def_id = mr.def_id();
598+
if def_id.krate != ast::LOCAL_CRATE {
599+
return false;
600+
}
601+
602+
let trait_item = self.tcx.map.expect_trait_item(def_id.node);
603+
if let ast::TraitItem_::MethodTraitItem(_, Some(_)) = trait_item.node {
604+
true
605+
} else {
606+
false
607+
}
608+
}
609+
597610
pub fn get_field_ref_data(&self,
598611
field_ref: &ast::Field,
599612
struct_id: DefId,

0 commit comments

Comments
 (0)