Cross crait inherant impls

This commit is contained in:
Nick Cameron 2014-10-20 14:30:31 +13:00
parent d416d16cce
commit 1397f990fe
3 changed files with 20 additions and 24 deletions

View file

@ -32,7 +32,7 @@ use syntax::parse::token;
use std::collections::hashmap::HashMap;
pub struct StaticMethodInfo {
pub struct MethodInfo {
pub name: ast::Name,
pub def_id: ast::DefId,
pub vis: ast::Visibility,
@ -177,11 +177,11 @@ pub fn get_type_name_if_impl(cstore: &cstore::CStore, def: ast::DefId)
decoder::get_type_name_if_impl(&*cdata, def.node)
}
pub fn get_static_methods_if_impl(cstore: &cstore::CStore,
pub fn get_methods_if_impl(cstore: &cstore::CStore,
def: ast::DefId)
-> Option<Vec<StaticMethodInfo> > {
-> Option<Vec<MethodInfo> > {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_static_methods_if_impl(cstore.intr.clone(), &*cdata, def.node)
decoder::get_methods_if_impl(cstore.intr.clone(), &*cdata, def.node)
}
pub fn get_item_attrs(cstore: &cstore::CStore,

View file

@ -15,7 +15,7 @@
use back::svh::Svh;
use metadata::cstore::crate_metadata;
use metadata::common::*;
use metadata::csearch::StaticMethodInfo;
use metadata::csearch::MethodInfo;
use metadata::csearch;
use metadata::cstore;
use metadata::tydecode::{parse_ty_data, parse_region_data, parse_def_id,
@ -902,10 +902,10 @@ pub fn get_type_name_if_impl(cdata: Cmd,
ret
}
pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
pub fn get_methods_if_impl(intr: Rc<IdentInterner>,
cdata: Cmd,
node_id: ast::NodeId)
-> Option<Vec<StaticMethodInfo> > {
-> Option<Vec<MethodInfo> > {
let item = lookup_item(node_id, cdata.data());
if item_family(item) != Impl {
return None;
@ -924,14 +924,14 @@ pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
true
});
let mut static_impl_methods = Vec::new();
let mut impl_methods = Vec::new();
for impl_method_id in impl_method_ids.iter() {
let impl_method_doc = lookup_item(impl_method_id.node, cdata.data());
let family = item_family(impl_method_doc);
match family {
StaticMethod => {
static_impl_methods.push(StaticMethodInfo {
name: item_name(&*intr, impl_method_doc),
StaticMethod | Method => {
impl_methods.push(MethodInfo {
ident: item_name(&*intr, impl_method_doc),
def_id: item_def_id(impl_method_doc, cdata),
vis: item_visibility(impl_method_doc),
});
@ -940,7 +940,7 @@ pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
}
}
return Some(static_impl_methods);
return Some(impl_methods);
}
/// If node_id is the constructor of a tuple struct, retrieve the NodeId of

View file

@ -1950,15 +1950,14 @@ impl<'a> Resolver<'a> {
}
}
DlImpl(def) => {
// We only process static methods of impls here.
match csearch::get_type_name_if_impl(&self.session.cstore, def) {
None => {}
Some(final_name) => {
let static_methods_opt =
csearch::get_static_methods_if_impl(&self.session.cstore, def);
match static_methods_opt {
Some(ref static_methods) if
static_methods.len() >= 1 => {
let methods_opt =
csearch::get_methods_if_impl(&self.session.cstore, def);
match methods_opt {
Some(ref methods) if
methods.len() >= 1 => {
debug!("(building reduced graph for \
external crate) processing \
static methods for type name {}",
@ -2008,9 +2007,8 @@ impl<'a> Resolver<'a> {
// Add each static method to the module.
let new_parent =
ModuleReducedGraphParent(type_module);
for static_method_info in
static_methods.iter() {
let name = static_method_info.name;
for method_info in methods.iter() {
let name = method_info.name;
debug!("(building reduced graph for \
external crate) creating \
static method '{}'",
@ -2021,9 +2019,7 @@ impl<'a> Resolver<'a> {
new_parent.clone(),
OverwriteDuplicates,
DUMMY_SP);
let def = DefFn(
static_method_info.def_id,
false);
let def = DefFn(method_info.def_id, false);
method_name_bindings.define_value(
def, DUMMY_SP,