Skip to content

Commit

Permalink
Cross crait inherant impls
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Oct 31, 2014
1 parent d416d16 commit 1397f99
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/librustc/metadata/csearch.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/metadata/decoder.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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),
});
Expand All @@ -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
Expand Down
20 changes: 8 additions & 12 deletions src/librustc/middle/resolve.rs
Expand Up @@ -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 {}",
Expand Down Expand Up @@ -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 '{}'",
Expand All @@ -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,
Expand Down

0 comments on commit 1397f99

Please sign in to comment.