提交 4e7d86c0 编写于 作者: N Nick Cameron

Resolve methods called as functions and...

...defined in another crate.

Fixes #18061
上级 5e834243
......@@ -115,6 +115,8 @@ enum Family {
CtorFn, // o
StaticMethod, // F
UnsafeStaticMethod, // U
Method, // h
UnsafeMethod, // H
Type, // y
ForeignType, // T
Mod, // m
......@@ -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,
......@@ -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
......
......@@ -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);
}
......@@ -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::*;
......@@ -1407,7 +1414,7 @@ fn add_to_index(item: &Item, rbml_w: &Encoder,
}
_ => {
encode_family(rbml_w,
style_fn_family(
fn_style_method_family(
method_ty.fty.fn_style));
}
}
......@@ -1432,30 +1439,30 @@ fn add_to_index(item: &Item, rbml_w: &Encoder,
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) => {
......
......@@ -1837,7 +1837,7 @@ fn handle_external_def(&mut self,
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);
......@@ -1902,11 +1902,6 @@ fn handle_external_def(&mut self,
// 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(..) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册