Skip to content

Commit 88b6e93

Browse files
committed
auto merge of #18177 : nick29581/rust/ufcs2, r=nikomatsakis
r? closes #18061
2 parents 5e83424 + 060566f commit 88b6e93

20 files changed

+263
-140
lines changed

src/librustc/metadata/csearch.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ use syntax::parse::token;
3232

3333
use std::collections::hashmap::HashMap;
3434

35-
pub struct StaticMethodInfo {
35+
pub struct MethodInfo {
3636
pub name: ast::Name,
3737
pub def_id: ast::DefId,
38-
pub fn_style: ast::FnStyle,
3938
pub vis: ast::Visibility,
4039
}
4140

@@ -178,11 +177,11 @@ pub fn get_type_name_if_impl(cstore: &cstore::CStore, def: ast::DefId)
178177
decoder::get_type_name_if_impl(&*cdata, def.node)
179178
}
180179

181-
pub fn get_static_methods_if_impl(cstore: &cstore::CStore,
180+
pub fn get_methods_if_impl(cstore: &cstore::CStore,
182181
def: ast::DefId)
183-
-> Option<Vec<StaticMethodInfo> > {
182+
-> Option<Vec<MethodInfo> > {
184183
let cdata = cstore.get_crate_data(def.krate);
185-
decoder::get_static_methods_if_impl(cstore.intr.clone(), &*cdata, def.node)
184+
decoder::get_methods_if_impl(cstore.intr.clone(), &*cdata, def.node)
186185
}
187186

188187
pub fn get_item_attrs(cstore: &cstore::CStore,

src/librustc/metadata/decoder.rs

+19-30
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use back::svh::Svh;
1616
use metadata::cstore::crate_metadata;
1717
use metadata::common::*;
18-
use metadata::csearch::StaticMethodInfo;
18+
use metadata::csearch::MethodInfo;
1919
use metadata::csearch;
2020
use metadata::cstore;
2121
use metadata::tydecode::{parse_ty_data, parse_region_data, parse_def_id,
@@ -111,10 +111,9 @@ enum Family {
111111
ImmStatic, // c
112112
MutStatic, // b
113113
Fn, // f
114-
UnsafeFn, // u
115114
CtorFn, // o
116115
StaticMethod, // F
117-
UnsafeStaticMethod, // U
116+
Method, // h
118117
Type, // y
119118
ForeignType, // T
120119
Mod, // m
@@ -137,10 +136,9 @@ fn item_family(item: rbml::Doc) -> Family {
137136
'c' => ImmStatic,
138137
'b' => MutStatic,
139138
'f' => Fn,
140-
'u' => UnsafeFn,
141139
'o' => CtorFn,
142140
'F' => StaticMethod,
143-
'U' => UnsafeStaticMethod,
141+
'h' => Method,
144142
'y' => Type,
145143
'T' => ForeignType,
146144
'm' => Mod,
@@ -309,15 +307,9 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
309307
ImmStatic => DlDef(def::DefStatic(did, false)),
310308
MutStatic => DlDef(def::DefStatic(did, true)),
311309
Struct => DlDef(def::DefStruct(did)),
312-
UnsafeFn => DlDef(def::DefFn(did, ast::UnsafeFn, false)),
313-
Fn => DlDef(def::DefFn(did, ast::NormalFn, false)),
314-
CtorFn => DlDef(def::DefFn(did, ast::NormalFn, true)),
315-
StaticMethod | UnsafeStaticMethod => {
316-
let fn_style = if fam == UnsafeStaticMethod {
317-
ast::UnsafeFn
318-
} else {
319-
ast::NormalFn
320-
};
310+
Fn => DlDef(def::DefFn(did, false)),
311+
CtorFn => DlDef(def::DefFn(did, true)),
312+
Method | StaticMethod => {
321313
// def_static_method carries an optional field of its enclosing
322314
// trait or enclosing impl (if this is an inherent static method).
323315
// So we need to detect whether this is in a trait or not, which
@@ -331,7 +323,12 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
331323
def::FromImpl(item_reqd_and_translated_parent_item(cnum,
332324
item))
333325
};
334-
DlDef(def::DefStaticMethod(did, provenance, fn_style))
326+
match fam {
327+
// We don't bother to get encode/decode the trait id, we don't need it.
328+
Method => DlDef(def::DefMethod(did, None, provenance)),
329+
StaticMethod => DlDef(def::DefStaticMethod(did, provenance)),
330+
_ => panic!()
331+
}
335332
}
336333
Type | ForeignType => DlDef(def::DefTy(did, false)),
337334
Mod => DlDef(def::DefMod(did)),
@@ -518,7 +515,7 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
518515
None => {}
519516
Some(impl_method_doc) => {
520517
match item_family(impl_method_doc) {
521-
StaticMethod | UnsafeStaticMethod => {
518+
StaticMethod => {
522519
// Hand off the static method
523520
// to the callback.
524521
let static_method_name =
@@ -905,10 +902,10 @@ pub fn get_type_name_if_impl(cdata: Cmd,
905902
ret
906903
}
907904

908-
pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
905+
pub fn get_methods_if_impl(intr: Rc<IdentInterner>,
909906
cdata: Cmd,
910907
node_id: ast::NodeId)
911-
-> Option<Vec<StaticMethodInfo> > {
908+
-> Option<Vec<MethodInfo> > {
912909
let item = lookup_item(node_id, cdata.data());
913910
if item_family(item) != Impl {
914911
return None;
@@ -927,31 +924,23 @@ pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
927924
true
928925
});
929926

930-
let mut static_impl_methods = Vec::new();
927+
let mut impl_methods = Vec::new();
931928
for impl_method_id in impl_method_ids.iter() {
932929
let impl_method_doc = lookup_item(impl_method_id.node, cdata.data());
933930
let family = item_family(impl_method_doc);
934931
match family {
935-
StaticMethod | UnsafeStaticMethod => {
936-
let fn_style;
937-
match item_family(impl_method_doc) {
938-
StaticMethod => fn_style = ast::NormalFn,
939-
UnsafeStaticMethod => fn_style = ast::UnsafeFn,
940-
_ => panic!()
941-
}
942-
943-
static_impl_methods.push(StaticMethodInfo {
932+
StaticMethod | Method => {
933+
impl_methods.push(MethodInfo {
944934
name: item_name(&*intr, impl_method_doc),
945935
def_id: item_def_id(impl_method_doc, cdata),
946-
fn_style: fn_style,
947936
vis: item_visibility(impl_method_doc),
948937
});
949938
}
950939
_ => {}
951940
}
952941
}
953942

954-
return Some(static_impl_methods);
943+
return Some(impl_methods);
955944
}
956945

957946
/// If node_id is the constructor of a tuple struct, retrieve the NodeId of

src/librustc/metadata/encoder.rs

+28-42
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,11 @@ fn encode_method_ty_fields(ecx: &EncodeContext,
835835
encode_method_fty(ecx, rbml_w, &method_ty.fty);
836836
encode_visibility(rbml_w, method_ty.vis);
837837
encode_explicit_self(rbml_w, &method_ty.explicit_self);
838-
let fn_style = method_ty.fty.fn_style;
839838
match method_ty.explicit_self {
840839
ty::StaticExplicitSelfCategory => {
841-
encode_family(rbml_w, fn_style_static_method_family(fn_style));
840+
encode_family(rbml_w, STATIC_METHOD_FAMILY);
842841
}
843-
_ => encode_family(rbml_w, style_fn_family(fn_style))
842+
_ => encode_family(rbml_w, METHOD_FAMILY)
844843
}
845844
encode_provided_source(rbml_w, method_ty.provided_source);
846845
}
@@ -964,20 +963,9 @@ fn encode_inlined_item(ecx: &EncodeContext,
964963
(*eii)(ecx, rbml_w, ii)
965964
}
966965

967-
fn style_fn_family(s: FnStyle) -> char {
968-
match s {
969-
UnsafeFn => 'u',
970-
NormalFn => 'f',
971-
}
972-
}
973-
974-
fn fn_style_static_method_family(s: FnStyle) -> char {
975-
match s {
976-
UnsafeFn => 'U',
977-
NormalFn => 'F',
978-
}
979-
}
980-
966+
const FN_FAMILY: char = 'f';
967+
const STATIC_METHOD_FAMILY: char = 'F';
968+
const METHOD_FAMILY: char = 'h';
981969

982970
fn should_inline(attrs: &[Attribute]) -> bool {
983971
use syntax::attr::*;
@@ -1081,11 +1069,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
10811069
encode_stability(rbml_w, stab);
10821070
rbml_w.end_tag();
10831071
}
1084-
ItemFn(ref decl, fn_style, _, ref generics, _) => {
1072+
ItemFn(ref decl, _, _, ref generics, _) => {
10851073
add_to_index(item, rbml_w, index);
10861074
rbml_w.start_tag(tag_items_data_item);
10871075
encode_def_id(rbml_w, def_id);
1088-
encode_family(rbml_w, style_fn_family(fn_style));
1076+
encode_family(rbml_w, FN_FAMILY);
10891077
let tps_len = generics.ty_params.len();
10901078
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
10911079
encode_name(rbml_w, item.ident.name);
@@ -1402,13 +1390,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
14021390
match method_ty.explicit_self {
14031391
ty::StaticExplicitSelfCategory => {
14041392
encode_family(rbml_w,
1405-
fn_style_static_method_family(
1406-
method_ty.fty.fn_style));
1393+
STATIC_METHOD_FAMILY);
14071394
}
14081395
_ => {
14091396
encode_family(rbml_w,
1410-
style_fn_family(
1411-
method_ty.fty.fn_style));
1397+
METHOD_FAMILY);
14121398
}
14131399
}
14141400
let pty = ty::lookup_item_type(tcx,
@@ -1432,30 +1418,30 @@ fn encode_info_for_item(ecx: &EncodeContext,
14321418
encode_parent_sort(rbml_w, 't');
14331419

14341420
let trait_item = &ms[i];
1435-
match &ms[i] {
1436-
&RequiredMethod(ref tm) => {
1437-
encode_attributes(rbml_w, tm.attrs.as_slice());
1421+
let encode_trait_item = |rbml_w: &mut Encoder| {
1422+
// If this is a static method, we've already
1423+
// encoded this.
1424+
if is_nonstatic_method {
1425+
// FIXME: I feel like there is something funny
1426+
// going on.
1427+
let pty = ty::lookup_item_type(tcx, item_def_id.def_id());
1428+
encode_bounds_and_type(rbml_w, ecx, &pty);
1429+
}
1430+
};
1431+
match trait_item {
1432+
&RequiredMethod(ref m) => {
1433+
encode_attributes(rbml_w, m.attrs.as_slice());
1434+
encode_trait_item(rbml_w);
14381435
encode_item_sort(rbml_w, 'r');
1439-
encode_method_argument_names(rbml_w, &*tm.decl);
1436+
encode_method_argument_names(rbml_w, &*m.decl);
14401437
}
14411438

14421439
&ProvidedMethod(ref m) => {
14431440
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-
}
1441+
encode_trait_item(rbml_w);
14531442
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());
1443+
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
1444+
encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
14591445
}
14601446

14611447
&TypeTraitItem(ref associated_type) => {
@@ -1493,7 +1479,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
14931479
encode_visibility(rbml_w, nitem.vis);
14941480
match nitem.node {
14951481
ForeignItemFn(..) => {
1496-
encode_family(rbml_w, style_fn_family(NormalFn));
1482+
encode_family(rbml_w, FN_FAMILY);
14971483
encode_bounds_and_type(rbml_w, ecx,
14981484
&lookup_item_type(ecx.tcx,local_def(nitem.id)));
14991485
encode_name(rbml_w, nitem.ident.name);

src/librustc/middle/astencode.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ fn decode_def(dcx: &DecodeContext, doc: rbml::Doc) -> def::Def {
440440
impl tr for def::Def {
441441
fn tr(&self, dcx: &DecodeContext) -> def::Def {
442442
match *self {
443-
def::DefFn(did, p, is_ctor) => def::DefFn(did.tr(dcx), p, is_ctor),
444-
def::DefStaticMethod(did, wrapped_did2, p) => {
443+
def::DefFn(did, is_ctor) => def::DefFn(did.tr(dcx), is_ctor),
444+
def::DefStaticMethod(did, wrapped_did2) => {
445445
def::DefStaticMethod(did.tr(dcx),
446446
match wrapped_did2 {
447447
def::FromTrait(did2) => {
@@ -450,8 +450,7 @@ impl tr for def::Def {
450450
def::FromImpl(did2) => {
451451
def::FromImpl(did2.tr(dcx))
452452
}
453-
},
454-
p)
453+
})
455454
}
456455
def::DefMethod(did0, did1, p) => {
457456
def::DefMethod(did0.tr(dcx), did1.map(|did1| did1.tr(dcx)), p)

src/librustc/middle/def.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use syntax::ast_util::local_def;
1414

1515
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
1616
pub enum Def {
17-
DefFn(ast::DefId, ast::FnStyle, bool /* is_ctor */),
18-
DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle),
17+
DefFn(ast::DefId, bool /* is_ctor */),
18+
DefStaticMethod(/* method */ ast::DefId, MethodProvenance),
1919
DefSelfTy(/* trait id */ ast::NodeId),
2020
DefMod(ast::DefId),
2121
DefForeignMod(ast::DefId),
@@ -58,7 +58,7 @@ pub enum MethodProvenance {
5858
impl Def {
5959
pub fn def_id(&self) -> ast::DefId {
6060
match *self {
61-
DefFn(id, _, _) | DefStaticMethod(id, _, _) | DefMod(id) |
61+
DefFn(id, _) | DefStaticMethod(id, _) | DefMod(id) |
6262
DefForeignMod(id) | DefStatic(id, _) |
6363
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(id) |
6464
DefTyParam(_, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) |

src/librustc/middle/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> {
121121
match expr.node {
122122
ast::ExprPath(..) => {
123123
match ty::resolve_expr(self.tcx, expr) {
124-
DefFn(did, _, _) if self.def_id_is_transmute(did) => {
124+
DefFn(did, _) if self.def_id_is_transmute(did) => {
125125
let typ = ty::node_id_to_type(self.tcx, expr.id);
126126
match ty::get(typ).sty {
127127
ty_bare_fn(ref bare_fn_ty)

0 commit comments

Comments
 (0)