Skip to content

Commit

Permalink
Resolve methods called as functions and...
Browse files Browse the repository at this point in the history
...defined in another crate.

Fixes #18061
  • Loading branch information
nrc committed Oct 31, 2014
1 parent 5e83424 commit 4e7d86c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/librustc/metadata/decoder.rs
Expand Up @@ -115,6 +115,8 @@ enum Family {
CtorFn, // o
StaticMethod, // F
UnsafeStaticMethod, // U
Method, // h
UnsafeMethod, // H
Type, // y
ForeignType, // T
Mod, // m
Expand All @@ -141,6 +143,8 @@ fn item_family(item: rbml::Doc) -> Family {
'o' => CtorFn,
'F' => StaticMethod,
'U' => UnsafeStaticMethod,
'h' => Method,
'H' => UnsafeMethod,
'y' => Type,
'T' => ForeignType,
'm' => Mod,
Expand Down Expand Up @@ -312,6 +316,8 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
UnsafeFn => DlDef(def::DefFn(did, ast::UnsafeFn, false)),
Fn => DlDef(def::DefFn(did, ast::NormalFn, false)),
CtorFn => DlDef(def::DefFn(did, ast::NormalFn, true)),
UnsafeMethod => DlDef(def::DefMethod(did, ast::UnsafeFn, false)),
Method => DlDef(def::DefMethod(did, ast::NormalFn, false)),
StaticMethod | UnsafeStaticMethod => {
let fn_style = if fam == UnsafeStaticMethod {
ast::UnsafeFn
Expand Down
47 changes: 27 additions & 20 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -840,7 +840,7 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
ty::StaticExplicitSelfCategory => {
encode_family(rbml_w, fn_style_static_method_family(fn_style));
}
_ => encode_family(rbml_w, style_fn_family(fn_style))
_ => encode_family(rbml_w, fn_style_method_family(fn_style))
}
encode_provided_source(rbml_w, method_ty.provided_source);
}
Expand Down Expand Up @@ -978,6 +978,13 @@ fn fn_style_static_method_family(s: FnStyle) -> char {
}
}

fn fn_style_method_family(s: FnStyle) -> char {
match s {
UnsafeFn => 'h',
NormalFn => 'H',
}
}


fn should_inline(attrs: &[Attribute]) -> bool {
use syntax::attr::*;
Expand Down Expand Up @@ -1407,7 +1414,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
_ => {
encode_family(rbml_w,
style_fn_family(
fn_style_method_family(
method_ty.fty.fn_style));
}
}
Expand All @@ -1432,30 +1439,30 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_parent_sort(rbml_w, 't');

let trait_item = &ms[i];
match &ms[i] {
&RequiredMethod(ref tm) => {
encode_attributes(rbml_w, tm.attrs.as_slice());
let foo = |rbml_w: &mut Encoder| {
// If this is a static method, we've already
// encoded this.
if is_nonstatic_method {
// FIXME: I feel like there is something funny
// going on.
let pty = ty::lookup_item_type(tcx, item_def_id.def_id());
encode_bounds_and_type(rbml_w, ecx, &pty);
}
};
match trait_item {
&RequiredMethod(ref m) => {
encode_attributes(rbml_w, m.attrs.as_slice());
foo(rbml_w);
encode_item_sort(rbml_w, 'r');
encode_method_argument_names(rbml_w, &*tm.decl);
encode_method_argument_names(rbml_w, &*m.decl);
}

&ProvidedMethod(ref m) => {
encode_attributes(rbml_w, m.attrs.as_slice());
// If this is a static method, we've already
// encoded this.
if is_nonstatic_method {
// FIXME: I feel like there is something funny
// going on.
let pty = ty::lookup_item_type(tcx,
item_def_id.def_id());
encode_bounds_and_type(rbml_w, ecx, &pty);
}
foo(rbml_w);
encode_item_sort(rbml_w, 'p');
encode_inlined_item(ecx,
rbml_w,
IITraitItemRef(def_id, trait_item));
encode_method_argument_names(rbml_w,
&*m.pe_fn_decl());
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
}

&TypeTraitItem(ref associated_type) => {
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/middle/resolve.rs
Expand Up @@ -1837,7 +1837,7 @@ impl<'a> Resolver<'a> {
csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
.map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, is_public);
}
DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) => {
DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) | DefMethod(..) => {
debug!("(building reduced graph for external \
crate) building value (fn/static) {}", final_ident);
child_name_bindings.define_value(def, DUMMY_SP, is_public);
Expand Down Expand Up @@ -1902,11 +1902,6 @@ impl<'a> Resolver<'a> {
// Record the def ID and fields of this struct.
self.structs.insert(def_id, fields);
}
DefMethod(..) => {
debug!("(building reduced graph for external crate) \
ignoring {}", def);
// Ignored; handled elsewhere.
}
DefLocal(..) | DefPrimTy(..) | DefTyParam(..) |
DefUse(..) | DefUpvar(..) | DefRegion(..) |
DefTyParamBinder(..) | DefLabel(..) | DefSelfTy(..) => {
Expand Down

0 comments on commit 4e7d86c

Please sign in to comment.