Skip to content

Commit 4e7d86c

Browse files
committed
Resolve methods called as functions and...
...defined in another crate. Fixes rust-lang#18061
1 parent 5e83424 commit 4e7d86c

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/librustc/metadata/decoder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ enum Family {
115115
CtorFn, // o
116116
StaticMethod, // F
117117
UnsafeStaticMethod, // U
118+
Method, // h
119+
UnsafeMethod, // H
118120
Type, // y
119121
ForeignType, // T
120122
Mod, // m
@@ -141,6 +143,8 @@ fn item_family(item: rbml::Doc) -> Family {
141143
'o' => CtorFn,
142144
'F' => StaticMethod,
143145
'U' => UnsafeStaticMethod,
146+
'h' => Method,
147+
'H' => UnsafeMethod,
144148
'y' => Type,
145149
'T' => ForeignType,
146150
'm' => Mod,
@@ -312,6 +316,8 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
312316
UnsafeFn => DlDef(def::DefFn(did, ast::UnsafeFn, false)),
313317
Fn => DlDef(def::DefFn(did, ast::NormalFn, false)),
314318
CtorFn => DlDef(def::DefFn(did, ast::NormalFn, true)),
319+
UnsafeMethod => DlDef(def::DefMethod(did, ast::UnsafeFn, false)),
320+
Method => DlDef(def::DefMethod(did, ast::NormalFn, false)),
315321
StaticMethod | UnsafeStaticMethod => {
316322
let fn_style = if fam == UnsafeStaticMethod {
317323
ast::UnsafeFn

src/librustc/metadata/encoder.rs

+27-20
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
840840
ty::StaticExplicitSelfCategory => {
841841
encode_family(rbml_w, fn_style_static_method_family(fn_style));
842842
}
843-
_ => encode_family(rbml_w, style_fn_family(fn_style))
843+
_ => encode_family(rbml_w, fn_style_method_family(fn_style))
844844
}
845845
encode_provided_source(rbml_w, method_ty.provided_source);
846846
}
@@ -978,6 +978,13 @@ fn fn_style_static_method_family(s: FnStyle) -> char {
978978
}
979979
}
980980

981+
fn fn_style_method_family(s: FnStyle) -> char {
982+
match s {
983+
UnsafeFn => 'h',
984+
NormalFn => 'H',
985+
}
986+
}
987+
981988

982989
fn should_inline(attrs: &[Attribute]) -> bool {
983990
use syntax::attr::*;
@@ -1407,7 +1414,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
14071414
}
14081415
_ => {
14091416
encode_family(rbml_w,
1410-
style_fn_family(
1417+
fn_style_method_family(
14111418
method_ty.fty.fn_style));
14121419
}
14131420
}
@@ -1432,30 +1439,30 @@ fn encode_info_for_item(ecx: &EncodeContext,
14321439
encode_parent_sort(rbml_w, 't');
14331440

14341441
let trait_item = &ms[i];
1435-
match &ms[i] {
1436-
&RequiredMethod(ref tm) => {
1437-
encode_attributes(rbml_w, tm.attrs.as_slice());
1442+
let foo = |rbml_w: &mut Encoder| {
1443+
// If this is a static method, we've already
1444+
// encoded this.
1445+
if is_nonstatic_method {
1446+
// FIXME: I feel like there is something funny
1447+
// going on.
1448+
let pty = ty::lookup_item_type(tcx, item_def_id.def_id());
1449+
encode_bounds_and_type(rbml_w, ecx, &pty);
1450+
}
1451+
};
1452+
match trait_item {
1453+
&RequiredMethod(ref m) => {
1454+
encode_attributes(rbml_w, m.attrs.as_slice());
1455+
foo(rbml_w);
14381456
encode_item_sort(rbml_w, 'r');
1439-
encode_method_argument_names(rbml_w, &*tm.decl);
1457+
encode_method_argument_names(rbml_w, &*m.decl);
14401458
}
14411459

14421460
&ProvidedMethod(ref m) => {
14431461
encode_attributes(rbml_w, m.attrs.as_slice());
1444-
// If this is a static method, we've already
1445-
// encoded this.
1446-
if is_nonstatic_method {
1447-
// FIXME: I feel like there is something funny
1448-
// going on.
1449-
let pty = ty::lookup_item_type(tcx,
1450-
item_def_id.def_id());
1451-
encode_bounds_and_type(rbml_w, ecx, &pty);
1452-
}
1462+
foo(rbml_w);
14531463
encode_item_sort(rbml_w, 'p');
1454-
encode_inlined_item(ecx,
1455-
rbml_w,
1456-
IITraitItemRef(def_id, trait_item));
1457-
encode_method_argument_names(rbml_w,
1458-
&*m.pe_fn_decl());
1464+
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
1465+
encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
14591466
}
14601467

14611468
&TypeTraitItem(ref associated_type) => {

src/librustc/middle/resolve.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ impl<'a> Resolver<'a> {
18371837
csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
18381838
.map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, is_public);
18391839
}
1840-
DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) => {
1840+
DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) | DefMethod(..) => {
18411841
debug!("(building reduced graph for external \
18421842
crate) building value (fn/static) {}", final_ident);
18431843
child_name_bindings.define_value(def, DUMMY_SP, is_public);
@@ -1902,11 +1902,6 @@ impl<'a> Resolver<'a> {
19021902
// Record the def ID and fields of this struct.
19031903
self.structs.insert(def_id, fields);
19041904
}
1905-
DefMethod(..) => {
1906-
debug!("(building reduced graph for external crate) \
1907-
ignoring {}", def);
1908-
// Ignored; handled elsewhere.
1909-
}
19101905
DefLocal(..) | DefPrimTy(..) | DefTyParam(..) |
19111906
DefUse(..) | DefUpvar(..) | DefRegion(..) |
19121907
DefTyParamBinder(..) | DefLabel(..) | DefSelfTy(..) => {

0 commit comments

Comments
 (0)