save-analysis: fix def_ids for method calls
We were sometime emitting the decl as a def.
This commit is contained in:
parent
94f13ac376
commit
49d3a93c52
@ -411,6 +411,13 @@ impl<'ast> Map<'ast> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_trait_item(&self, id: NodeId) -> &'ast TraitItem {
|
||||
match self.find(id) {
|
||||
Some(NodeTraitItem(item)) => item,
|
||||
_ => panic!("expected trait item, found {}", self.node_to_string(id))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
|
||||
match self.find(id) {
|
||||
Some(NodeItem(i)) => {
|
||||
|
@ -548,13 +548,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
let ti = self.tcx.impl_or_trait_item(decl_id);
|
||||
match provenence {
|
||||
def::FromTrait(def_id) => {
|
||||
Some(self.tcx.trait_items(def_id)
|
||||
.iter()
|
||||
.find(|mr| {
|
||||
mr.name() == ti.name()
|
||||
})
|
||||
.unwrap()
|
||||
.def_id())
|
||||
self.tcx.trait_items(def_id)
|
||||
.iter()
|
||||
.find(|mr| {
|
||||
mr.name() == ti.name() && self.trait_method_has_body(mr)
|
||||
})
|
||||
.map(|mr| mr.def_id())
|
||||
}
|
||||
def::FromImpl(def_id) => {
|
||||
let impl_items = self.tcx.impl_items.borrow();
|
||||
@ -594,6 +593,20 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn trait_method_has_body(&self, mr: &ty::ImplOrTraitItem) -> bool {
|
||||
let def_id = mr.def_id();
|
||||
if def_id.krate != ast::LOCAL_CRATE {
|
||||
return false;
|
||||
}
|
||||
|
||||
let trait_item = self.tcx.map.expect_trait_item(def_id.node);
|
||||
if let ast::TraitItem_::MethodTraitItem(_, Some(_)) = trait_item.node {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_field_ref_data(&self,
|
||||
field_ref: &ast::Field,
|
||||
struct_id: DefId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user