Skip to content

Commit d416d16

Browse files
committed
Remove FnStyle from DefFn and DefStaticMethod
1 parent 4e7d86c commit d416d16

File tree

14 files changed

+52
-95
lines changed

14 files changed

+52
-95
lines changed

src/librustc/metadata/csearch.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use std::collections::hashmap::HashMap;
3535
pub struct StaticMethodInfo {
3636
pub name: ast::Name,
3737
pub def_id: ast::DefId,
38-
pub fn_style: ast::FnStyle,
3938
pub vis: ast::Visibility,
4039
}
4140

src/librustc/metadata/decoder.rs

+11-28
Original file line numberDiff line numberDiff line change
@@ -111,12 +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
118116
Method, // h
119-
UnsafeMethod, // H
120117
Type, // y
121118
ForeignType, // T
122119
Mod, // m
@@ -139,12 +136,9 @@ fn item_family(item: rbml::Doc) -> Family {
139136
'c' => ImmStatic,
140137
'b' => MutStatic,
141138
'f' => Fn,
142-
'u' => UnsafeFn,
143139
'o' => CtorFn,
144140
'F' => StaticMethod,
145-
'U' => UnsafeStaticMethod,
146141
'h' => Method,
147-
'H' => UnsafeMethod,
148142
'y' => Type,
149143
'T' => ForeignType,
150144
'm' => Mod,
@@ -313,17 +307,9 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
313307
ImmStatic => DlDef(def::DefStatic(did, false)),
314308
MutStatic => DlDef(def::DefStatic(did, true)),
315309
Struct => DlDef(def::DefStruct(did)),
316-
UnsafeFn => DlDef(def::DefFn(did, ast::UnsafeFn, false)),
317-
Fn => DlDef(def::DefFn(did, ast::NormalFn, false)),
318-
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)),
321-
StaticMethod | UnsafeStaticMethod => {
322-
let fn_style = if fam == UnsafeStaticMethod {
323-
ast::UnsafeFn
324-
} else {
325-
ast::NormalFn
326-
};
310+
Fn => DlDef(def::DefFn(did, false)),
311+
CtorFn => DlDef(def::DefFn(did, true)),
312+
Method | StaticMethod => {
327313
// def_static_method carries an optional field of its enclosing
328314
// trait or enclosing impl (if this is an inherent static method).
329315
// So we need to detect whether this is in a trait or not, which
@@ -337,7 +323,12 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
337323
def::FromImpl(item_reqd_and_translated_parent_item(cnum,
338324
item))
339325
};
340-
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+
_ => fail!()
331+
}
341332
}
342333
Type | ForeignType => DlDef(def::DefTy(did, false)),
343334
Mod => DlDef(def::DefMod(did)),
@@ -524,7 +515,7 @@ fn each_child_of_item_or_crate(intr: Rc<IdentInterner>,
524515
None => {}
525516
Some(impl_method_doc) => {
526517
match item_family(impl_method_doc) {
527-
StaticMethod | UnsafeStaticMethod => {
518+
StaticMethod => {
528519
// Hand off the static method
529520
// to the callback.
530521
let static_method_name =
@@ -938,18 +929,10 @@ pub fn get_static_methods_if_impl(intr: Rc<IdentInterner>,
938929
let impl_method_doc = lookup_item(impl_method_id.node, cdata.data());
939930
let family = item_family(impl_method_doc);
940931
match family {
941-
StaticMethod | UnsafeStaticMethod => {
942-
let fn_style;
943-
match item_family(impl_method_doc) {
944-
StaticMethod => fn_style = ast::NormalFn,
945-
UnsafeStaticMethod => fn_style = ast::UnsafeFn,
946-
_ => panic!()
947-
}
948-
932+
StaticMethod => {
949933
static_impl_methods.push(StaticMethodInfo {
950934
name: item_name(&*intr, impl_method_doc),
951935
def_id: item_def_id(impl_method_doc, cdata),
952-
fn_style: fn_style,
953936
vis: item_visibility(impl_method_doc),
954937
});
955938
}

src/librustc/metadata/encoder.rs

+10-31
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, fn_style_method_family(fn_style))
842+
_ => encode_family(rbml_w, METHOD_FAMILY)
844843
}
845844
encode_provided_source(rbml_w, method_ty.provided_source);
846845
}
@@ -964,27 +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-
981-
fn fn_style_method_family(s: FnStyle) -> char {
982-
match s {
983-
UnsafeFn => 'h',
984-
NormalFn => 'H',
985-
}
986-
}
987-
966+
const FN_FAMILY: char = 'f';
967+
const STATIC_METHOD_FAMILY: char = 'F';
968+
const METHOD_FAMILY: char = 'h';
988969

989970
fn should_inline(attrs: &[Attribute]) -> bool {
990971
use syntax::attr::*;
@@ -1088,11 +1069,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
10881069
encode_stability(rbml_w, stab);
10891070
rbml_w.end_tag();
10901071
}
1091-
ItemFn(ref decl, fn_style, _, ref generics, _) => {
1072+
ItemFn(ref decl, _, _, ref generics, _) => {
10921073
add_to_index(item, rbml_w, index);
10931074
rbml_w.start_tag(tag_items_data_item);
10941075
encode_def_id(rbml_w, def_id);
1095-
encode_family(rbml_w, style_fn_family(fn_style));
1076+
encode_family(rbml_w, FN_FAMILY);
10961077
let tps_len = generics.ty_params.len();
10971078
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
10981079
encode_name(rbml_w, item.ident.name);
@@ -1409,13 +1390,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
14091390
match method_ty.explicit_self {
14101391
ty::StaticExplicitSelfCategory => {
14111392
encode_family(rbml_w,
1412-
fn_style_static_method_family(
1413-
method_ty.fty.fn_style));
1393+
STATIC_METHOD_FAMILY);
14141394
}
14151395
_ => {
14161396
encode_family(rbml_w,
1417-
fn_style_method_family(
1418-
method_ty.fty.fn_style));
1397+
METHOD_FAMILY);
14191398
}
14201399
}
14211400
let pty = ty::lookup_item_type(tcx,
@@ -1500,7 +1479,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
15001479
encode_visibility(rbml_w, nitem.vis);
15011480
match nitem.node {
15021481
ForeignItemFn(..) => {
1503-
encode_family(rbml_w, style_fn_family(NormalFn));
1482+
encode_family(rbml_w, FN_FAMILY);
15041483
encode_bounds_and_type(rbml_w, ecx,
15051484
&lookup_item_type(ecx.tcx,local_def(nitem.id)));
15061485
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)

src/librustc/middle/resolve.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt};
4141
use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyProc, TyQPath};
4242
use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint};
4343
use syntax::ast::{TypeImplItem, UnboxedFnTyParamBound, UnnamedField};
44-
use syntax::ast::{UnsafeFn, Variant, ViewItem, ViewItemExternCrate};
44+
use syntax::ast::{Variant, ViewItem, ViewItemExternCrate};
4545
use syntax::ast::{ViewItemUse, ViewPathGlob, ViewPathList, ViewPathSimple};
4646
use syntax::ast::{Visibility};
4747
use syntax::ast;
@@ -1250,11 +1250,11 @@ impl<'a> Resolver<'a> {
12501250
sp, is_public);
12511251
parent
12521252
}
1253-
ItemFn(_, fn_style, _, _, _) => {
1253+
ItemFn(_, _, _, _, _) => {
12541254
let name_bindings =
12551255
self.add_child(name, parent.clone(), ForbidDuplicateValues, sp);
12561256

1257-
let def = DefFn(local_def(item.id), fn_style, false);
1257+
let def = DefFn(local_def(item.id), false);
12581258
name_bindings.define_value(def, sp, is_public);
12591259
parent
12601260
}
@@ -1392,8 +1392,7 @@ impl<'a> Resolver<'a> {
13921392
// Static methods become
13931393
// `DefStaticMethod`s.
13941394
DefStaticMethod(local_def(method.id),
1395-
FromImpl(local_def(item.id)),
1396-
method.pe_fn_style())
1395+
FromImpl(local_def(item.id)))
13971396
}
13981397
_ => {
13991398
// Non-static methods become
@@ -1483,8 +1482,7 @@ impl<'a> Resolver<'a> {
14831482
// Static methods become `DefStaticMethod`s.
14841483
(DefStaticMethod(
14851484
local_def(ty_m.id),
1486-
FromTrait(local_def(item.id)),
1487-
ty_m.fn_style),
1485+
FromTrait(local_def(item.id))),
14881486
StaticMethodTraitItemKind)
14891487
}
14901488
_ => {
@@ -1711,7 +1709,7 @@ impl<'a> Resolver<'a> {
17111709

17121710
match foreign_item.node {
17131711
ForeignItemFn(_, ref generics) => {
1714-
let def = DefFn(local_def(foreign_item.id), UnsafeFn, false);
1712+
let def = DefFn(local_def(foreign_item.id), false);
17151713
name_bindings.define_value(def, foreign_item.span, is_public);
17161714

17171715
self.with_type_parameter_rib(
@@ -1832,7 +1830,7 @@ impl<'a> Resolver<'a> {
18321830
child_name_bindings.define_value(def, DUMMY_SP, is_exported);
18331831
}
18341832
}
1835-
DefFn(ctor_id, _, true) => {
1833+
DefFn(ctor_id, true) => {
18361834
child_name_bindings.define_value(
18371835
csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
18381836
.map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, is_public);
@@ -2025,7 +2023,6 @@ impl<'a> Resolver<'a> {
20252023
DUMMY_SP);
20262024
let def = DefFn(
20272025
static_method_info.def_id,
2028-
static_method_info.fn_style,
20292026
false);
20302027

20312028
method_name_bindings.define_value(
@@ -5641,7 +5638,7 @@ impl<'a> Resolver<'a> {
56415638
Some(binding) => {
56425639
let p_str = self.path_names_to_string(&path);
56435640
match binding.def_for_namespace(ValueNS) {
5644-
Some(DefStaticMethod(_, provenance, _)) => {
5641+
Some(DefStaticMethod(_, provenance)) => {
56455642
match provenance {
56465643
FromImpl(_) => return StaticMethod(p_str),
56475644
FromTrait(_) => unreachable!()

src/librustc/middle/save/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
241241
def::DefRegion(_) |
242242
def::DefTyParamBinder(_) |
243243
def::DefLabel(_) |
244-
def::DefStaticMethod(_, _, _) |
244+
def::DefStaticMethod(..) |
245245
def::DefTyParam(..) |
246246
def::DefUse(_) |
247247
def::DefMethod(..) |
@@ -783,7 +783,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
783783
sub_span,
784784
def_id,
785785
self.cur_scope),
786-
def::DefStaticMethod(declid, provenence, _) => {
786+
def::DefStaticMethod(declid, provenence) => {
787787
let sub_span = self.span.sub_span_for_meth_name(ex.span);
788788
let defid = if declid.krate == ast::LOCAL_CRATE {
789789
let ti = ty::impl_or_trait_item(&self.analysis.ty_cx,
@@ -825,7 +825,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
825825
Some(declid),
826826
self.cur_scope);
827827
},
828-
def::DefFn(def_id, _, _) => self.fmt.fn_call_str(ex.span,
828+
def::DefFn(def_id, _) => self.fmt.fn_call_str(ex.span,
829829
sub_span,
830830
def_id,
831831
self.cur_scope),
@@ -835,7 +835,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
835835
}
836836
// modules or types in the path prefix
837837
match *def {
838-
def::DefStaticMethod(_, _, _) => {
838+
def::DefStaticMethod(..) => {
839839
self.write_sub_path_trait_truncated(path);
840840
},
841841
def::DefLocal(_) |

src/librustc/middle/trans/callee.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
144144
debug!("trans_def(def={}, ref_expr={})", def.repr(bcx.tcx()), ref_expr.repr(bcx.tcx()));
145145
let expr_ty = node_id_type(bcx, ref_expr.id);
146146
match def {
147-
def::DefFn(did, _, _) if {
147+
def::DefFn(did, _) if {
148148
let maybe_def_id = inline::get_local_instance(bcx.ccx(), did);
149149
let maybe_ast_node = maybe_def_id.and_then(|def_id| bcx.tcx().map
150150
.find(def_id.node));
@@ -159,19 +159,19 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
159159
data: NamedTupleConstructor(substs, 0)
160160
}
161161
}
162-
def::DefFn(did, _, _) if match ty::get(expr_ty).sty {
162+
def::DefFn(did, _) if match ty::get(expr_ty).sty {
163163
ty::ty_bare_fn(ref f) => f.abi == synabi::RustIntrinsic,
164164
_ => false
165165
} => {
166166
let substs = node_id_substs(bcx, ExprId(ref_expr.id));
167167
let def_id = inline::maybe_instantiate_inline(bcx.ccx(), did);
168168
Callee { bcx: bcx, data: Intrinsic(def_id.node, substs) }
169169
}
170-
def::DefFn(did, _, _) | def::DefMethod(did, _, def::FromImpl(_)) |
171-
def::DefStaticMethod(did, def::FromImpl(_), _) => {
170+
def::DefFn(did, _) | def::DefMethod(did, _, def::FromImpl(_)) |
171+
def::DefStaticMethod(did, def::FromImpl(_)) => {
172172
fn_callee(bcx, trans_fn_ref(bcx, did, ExprId(ref_expr.id)))
173173
}
174-
def::DefStaticMethod(meth_did, def::FromTrait(trait_did), _) |
174+
def::DefStaticMethod(meth_did, def::FromTrait(trait_did)) |
175175
def::DefMethod(meth_did, _, def::FromTrait(trait_did)) => {
176176
fn_callee(bcx, meth::trans_static_method_callee(bcx, meth_did,
177177
trait_did,

src/librustc/middle/trans/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
554554
is_local: bool) -> ValueRef {
555555

556556
let def_id = match def {
557-
def::DefFn(did, _, _) | def::DefStaticMethod(did, _, _) |
557+
def::DefFn(did, _) | def::DefStaticMethod(did, _) |
558558
def::DefVariant(_, did, _) | def::DefStruct(did) => did,
559559
_ => {
560560
ccx.sess().bug(format!("get_wrapper_for_bare_fn: \

src/librustc/middle/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
629629

630630
let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id);
631631
match opt_def {
632-
Some(def::DefFn(def_id, _fn_style, _)) => {
632+
Some(def::DefFn(def_id, _)) => {
633633
if !ast_util::is_local(def_id) {
634634
let ty = csearch::get_type(cx.tcx(), def_id).ty;
635635
base::trans_external_path(cx, def_id, ty)

0 commit comments

Comments
 (0)