diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 507aaf137cdf5..13b734a84a401 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -35,7 +35,6 @@ use std::collections::hashmap::HashMap; pub struct StaticMethodInfo { pub name: ast::Name, pub def_id: ast::DefId, - pub fn_style: ast::FnStyle, pub vis: ast::Visibility, } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index d72b370864a82..7fc417ddc1817 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -111,12 +111,9 @@ enum Family { ImmStatic, // c MutStatic, // b Fn, // f - UnsafeFn, // u CtorFn, // o StaticMethod, // F - UnsafeStaticMethod, // U Method, // h - UnsafeMethod, // H Type, // y ForeignType, // T Mod, // m @@ -139,12 +136,9 @@ fn item_family(item: rbml::Doc) -> Family { 'c' => ImmStatic, 'b' => MutStatic, 'f' => Fn, - 'u' => UnsafeFn, 'o' => CtorFn, 'F' => StaticMethod, - 'U' => UnsafeStaticMethod, 'h' => Method, - 'H' => UnsafeMethod, 'y' => Type, 'T' => ForeignType, 'm' => Mod, @@ -313,17 +307,9 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum) ImmStatic => DlDef(def::DefStatic(did, false)), MutStatic => DlDef(def::DefStatic(did, true)), Struct => DlDef(def::DefStruct(did)), - 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 - } else { - ast::NormalFn - }; + Fn => DlDef(def::DefFn(did, false)), + CtorFn => DlDef(def::DefFn(did, true)), + Method | StaticMethod => { // def_static_method carries an optional field of its enclosing // trait or enclosing impl (if this is an inherent static method). // 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) def::FromImpl(item_reqd_and_translated_parent_item(cnum, item)) }; - DlDef(def::DefStaticMethod(did, provenance, fn_style)) + match fam { + // We don't bother to get encode/decode the trait id, we don't need it. + Method => DlDef(def::DefMethod(did, None, provenance)), + StaticMethod => DlDef(def::DefStaticMethod(did, provenance)), + _ => fail!() + } } Type | ForeignType => DlDef(def::DefTy(did, false)), Mod => DlDef(def::DefMod(did)), @@ -524,7 +515,7 @@ fn each_child_of_item_or_crate(intr: Rc, None => {} Some(impl_method_doc) => { match item_family(impl_method_doc) { - StaticMethod | UnsafeStaticMethod => { + StaticMethod => { // Hand off the static method // to the callback. let static_method_name = @@ -938,18 +929,10 @@ pub fn get_static_methods_if_impl(intr: Rc, let impl_method_doc = lookup_item(impl_method_id.node, cdata.data()); let family = item_family(impl_method_doc); match family { - StaticMethod | UnsafeStaticMethod => { - let fn_style; - match item_family(impl_method_doc) { - StaticMethod => fn_style = ast::NormalFn, - UnsafeStaticMethod => fn_style = ast::UnsafeFn, - _ => panic!() - } - + StaticMethod => { static_impl_methods.push(StaticMethodInfo { name: item_name(&*intr, impl_method_doc), def_id: item_def_id(impl_method_doc, cdata), - fn_style: fn_style, vis: item_visibility(impl_method_doc), }); } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 2769d71327370..f3f802f35baea 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -835,12 +835,11 @@ fn encode_method_ty_fields(ecx: &EncodeContext, encode_method_fty(ecx, rbml_w, &method_ty.fty); encode_visibility(rbml_w, method_ty.vis); encode_explicit_self(rbml_w, &method_ty.explicit_self); - let fn_style = method_ty.fty.fn_style; match method_ty.explicit_self { ty::StaticExplicitSelfCategory => { - encode_family(rbml_w, fn_style_static_method_family(fn_style)); + encode_family(rbml_w, STATIC_METHOD_FAMILY); } - _ => encode_family(rbml_w, fn_style_method_family(fn_style)) + _ => encode_family(rbml_w, METHOD_FAMILY) } encode_provided_source(rbml_w, method_ty.provided_source); } @@ -964,27 +963,9 @@ fn encode_inlined_item(ecx: &EncodeContext, (*eii)(ecx, rbml_w, ii) } -fn style_fn_family(s: FnStyle) -> char { - match s { - UnsafeFn => 'u', - NormalFn => 'f', - } -} - -fn fn_style_static_method_family(s: FnStyle) -> char { - match s { - UnsafeFn => 'U', - NormalFn => 'F', - } -} - -fn fn_style_method_family(s: FnStyle) -> char { - match s { - UnsafeFn => 'h', - NormalFn => 'H', - } -} - +const FN_FAMILY: char = 'f'; +const STATIC_METHOD_FAMILY: char = 'F'; +const METHOD_FAMILY: char = 'h'; fn should_inline(attrs: &[Attribute]) -> bool { use syntax::attr::*; @@ -1088,11 +1069,11 @@ fn encode_info_for_item(ecx: &EncodeContext, encode_stability(rbml_w, stab); rbml_w.end_tag(); } - ItemFn(ref decl, fn_style, _, ref generics, _) => { + ItemFn(ref decl, _, _, ref generics, _) => { add_to_index(item, rbml_w, index); rbml_w.start_tag(tag_items_data_item); encode_def_id(rbml_w, def_id); - encode_family(rbml_w, style_fn_family(fn_style)); + encode_family(rbml_w, FN_FAMILY); let tps_len = generics.ty_params.len(); encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id)); encode_name(rbml_w, item.ident.name); @@ -1409,13 +1390,11 @@ fn encode_info_for_item(ecx: &EncodeContext, match method_ty.explicit_self { ty::StaticExplicitSelfCategory => { encode_family(rbml_w, - fn_style_static_method_family( - method_ty.fty.fn_style)); + STATIC_METHOD_FAMILY); } _ => { encode_family(rbml_w, - fn_style_method_family( - method_ty.fty.fn_style)); + METHOD_FAMILY); } } let pty = ty::lookup_item_type(tcx, @@ -1500,7 +1479,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext, encode_visibility(rbml_w, nitem.vis); match nitem.node { ForeignItemFn(..) => { - encode_family(rbml_w, style_fn_family(NormalFn)); + encode_family(rbml_w, FN_FAMILY); encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(ecx.tcx,local_def(nitem.id))); encode_name(rbml_w, nitem.ident.name); diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index f6d85a8eb018f..3d2bd763a1434 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -440,8 +440,8 @@ fn decode_def(dcx: &DecodeContext, doc: rbml::Doc) -> def::Def { impl tr for def::Def { fn tr(&self, dcx: &DecodeContext) -> def::Def { match *self { - def::DefFn(did, p, is_ctor) => def::DefFn(did.tr(dcx), p, is_ctor), - def::DefStaticMethod(did, wrapped_did2, p) => { + def::DefFn(did, is_ctor) => def::DefFn(did.tr(dcx), is_ctor), + def::DefStaticMethod(did, wrapped_did2) => { def::DefStaticMethod(did.tr(dcx), match wrapped_did2 { def::FromTrait(did2) => { @@ -450,8 +450,7 @@ impl tr for def::Def { def::FromImpl(did2) => { def::FromImpl(did2.tr(dcx)) } - }, - p) + }) } def::DefMethod(did0, did1, p) => { def::DefMethod(did0.tr(dcx), did1.map(|did1| did1.tr(dcx)), p) diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index f88269ccac947..a71f714a2efd7 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -14,8 +14,8 @@ use syntax::ast_util::local_def; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Def { - DefFn(ast::DefId, ast::FnStyle, bool /* is_ctor */), - DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle), + DefFn(ast::DefId, bool /* is_ctor */), + DefStaticMethod(/* method */ ast::DefId, MethodProvenance), DefSelfTy(/* trait id */ ast::NodeId), DefMod(ast::DefId), DefForeignMod(ast::DefId), @@ -58,7 +58,7 @@ pub enum MethodProvenance { impl Def { pub fn def_id(&self) -> ast::DefId { match *self { - DefFn(id, _, _) | DefStaticMethod(id, _, _) | DefMod(id) | + DefFn(id, _) | DefStaticMethod(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) | DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(id) | DefTyParam(_, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) | diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 1dd823539b4c6..2c7c360bb1df6 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -121,7 +121,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IntrinsicCheckingVisitor<'a, 'tcx> { match expr.node { ast::ExprPath(..) => { match ty::resolve_expr(self.tcx, expr) { - DefFn(did, _, _) if self.def_id_is_transmute(did) => { + DefFn(did, _) if self.def_id_is_transmute(did) => { let typ = ty::node_id_to_type(self.tcx, expr.id); match ty::get(typ).sty { ty_bare_fn(ref bare_fn_ty) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 7b21b8666e2b8..cbda829804b78 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -41,7 +41,7 @@ use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt}; use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyProc, TyQPath}; use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint}; use syntax::ast::{TypeImplItem, UnboxedFnTyParamBound, UnnamedField}; -use syntax::ast::{UnsafeFn, Variant, ViewItem, ViewItemExternCrate}; +use syntax::ast::{Variant, ViewItem, ViewItemExternCrate}; use syntax::ast::{ViewItemUse, ViewPathGlob, ViewPathList, ViewPathSimple}; use syntax::ast::{Visibility}; use syntax::ast; @@ -1250,11 +1250,11 @@ impl<'a> Resolver<'a> { sp, is_public); parent } - ItemFn(_, fn_style, _, _, _) => { + ItemFn(_, _, _, _, _) => { let name_bindings = self.add_child(name, parent.clone(), ForbidDuplicateValues, sp); - let def = DefFn(local_def(item.id), fn_style, false); + let def = DefFn(local_def(item.id), false); name_bindings.define_value(def, sp, is_public); parent } @@ -1392,8 +1392,7 @@ impl<'a> Resolver<'a> { // Static methods become // `DefStaticMethod`s. DefStaticMethod(local_def(method.id), - FromImpl(local_def(item.id)), - method.pe_fn_style()) + FromImpl(local_def(item.id))) } _ => { // Non-static methods become @@ -1483,8 +1482,7 @@ impl<'a> Resolver<'a> { // Static methods become `DefStaticMethod`s. (DefStaticMethod( local_def(ty_m.id), - FromTrait(local_def(item.id)), - ty_m.fn_style), + FromTrait(local_def(item.id))), StaticMethodTraitItemKind) } _ => { @@ -1711,7 +1709,7 @@ impl<'a> Resolver<'a> { match foreign_item.node { ForeignItemFn(_, ref generics) => { - let def = DefFn(local_def(foreign_item.id), UnsafeFn, false); + let def = DefFn(local_def(foreign_item.id), false); name_bindings.define_value(def, foreign_item.span, is_public); self.with_type_parameter_rib( @@ -1832,7 +1830,7 @@ impl<'a> Resolver<'a> { child_name_bindings.define_value(def, DUMMY_SP, is_exported); } } - DefFn(ctor_id, _, true) => { + DefFn(ctor_id, true) => { child_name_bindings.define_value( csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id) .map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, is_public); @@ -2025,7 +2023,6 @@ impl<'a> Resolver<'a> { DUMMY_SP); let def = DefFn( static_method_info.def_id, - static_method_info.fn_style, false); method_name_bindings.define_value( @@ -5641,7 +5638,7 @@ impl<'a> Resolver<'a> { Some(binding) => { let p_str = self.path_names_to_string(&path); match binding.def_for_namespace(ValueNS) { - Some(DefStaticMethod(_, provenance, _)) => { + Some(DefStaticMethod(_, provenance)) => { match provenance { FromImpl(_) => return StaticMethod(p_str), FromTrait(_) => unreachable!() diff --git a/src/librustc/middle/save/mod.rs b/src/librustc/middle/save/mod.rs index 4748de01240cf..90a21d4790378 100644 --- a/src/librustc/middle/save/mod.rs +++ b/src/librustc/middle/save/mod.rs @@ -241,7 +241,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { def::DefRegion(_) | def::DefTyParamBinder(_) | def::DefLabel(_) | - def::DefStaticMethod(_, _, _) | + def::DefStaticMethod(..) | def::DefTyParam(..) | def::DefUse(_) | def::DefMethod(..) | @@ -783,7 +783,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { sub_span, def_id, self.cur_scope), - def::DefStaticMethod(declid, provenence, _) => { + def::DefStaticMethod(declid, provenence) => { let sub_span = self.span.sub_span_for_meth_name(ex.span); let defid = if declid.krate == ast::LOCAL_CRATE { let ti = ty::impl_or_trait_item(&self.analysis.ty_cx, @@ -825,7 +825,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { Some(declid), self.cur_scope); }, - def::DefFn(def_id, _, _) => self.fmt.fn_call_str(ex.span, + def::DefFn(def_id, _) => self.fmt.fn_call_str(ex.span, sub_span, def_id, self.cur_scope), @@ -835,7 +835,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { } // modules or types in the path prefix match *def { - def::DefStaticMethod(_, _, _) => { + def::DefStaticMethod(..) => { self.write_sub_path_trait_truncated(path); }, def::DefLocal(_) | diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 1f4a0dadc0209..6addd9144409c 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -144,7 +144,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) debug!("trans_def(def={}, ref_expr={})", def.repr(bcx.tcx()), ref_expr.repr(bcx.tcx())); let expr_ty = node_id_type(bcx, ref_expr.id); match def { - def::DefFn(did, _, _) if { + def::DefFn(did, _) if { let maybe_def_id = inline::get_local_instance(bcx.ccx(), did); let maybe_ast_node = maybe_def_id.and_then(|def_id| bcx.tcx().map .find(def_id.node)); @@ -159,7 +159,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) data: NamedTupleConstructor(substs, 0) } } - def::DefFn(did, _, _) if match ty::get(expr_ty).sty { + def::DefFn(did, _) if match ty::get(expr_ty).sty { ty::ty_bare_fn(ref f) => f.abi == synabi::RustIntrinsic, _ => false } => { @@ -167,11 +167,11 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) let def_id = inline::maybe_instantiate_inline(bcx.ccx(), did); Callee { bcx: bcx, data: Intrinsic(def_id.node, substs) } } - def::DefFn(did, _, _) | def::DefMethod(did, _, def::FromImpl(_)) | - def::DefStaticMethod(did, def::FromImpl(_), _) => { + def::DefFn(did, _) | def::DefMethod(did, _, def::FromImpl(_)) | + def::DefStaticMethod(did, def::FromImpl(_)) => { fn_callee(bcx, trans_fn_ref(bcx, did, ExprId(ref_expr.id))) } - def::DefStaticMethod(meth_did, def::FromTrait(trait_did), _) | + def::DefStaticMethod(meth_did, def::FromTrait(trait_did)) | def::DefMethod(meth_did, _, def::FromTrait(trait_did)) => { fn_callee(bcx, meth::trans_static_method_callee(bcx, meth_did, trait_did, diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 717f52d739ddf..44613e85a82cb 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -554,7 +554,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, is_local: bool) -> ValueRef { let def_id = match def { - def::DefFn(did, _, _) | def::DefStaticMethod(did, _, _) | + def::DefFn(did, _) | def::DefStaticMethod(did, _) | def::DefVariant(_, did, _) | def::DefStruct(did) => did, _ => { ccx.sess().bug(format!("get_wrapper_for_bare_fn: \ diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 2f193754c1a50..6ba6ff6fb2113 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -629,7 +629,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id); match opt_def { - Some(def::DefFn(def_id, _fn_style, _)) => { + Some(def::DefFn(def_id, _)) => { if !ast_util::is_local(def_id) { let ty = csearch::get_type(cx.tcx(), def_id).ty; base::trans_external_path(cx, def_id, ty) diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 3bfa6af4a9bcb..f516c6106a991 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1189,13 +1189,13 @@ fn trans_def_fn_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let _icx = push_ctxt("trans_def_datum_unadjusted"); let llfn = match def { - def::DefFn(did, _, _) | + def::DefFn(did, _) | def::DefStruct(did) | def::DefVariant(_, did, _) | - def::DefStaticMethod(did, def::FromImpl(_), _) | + def::DefStaticMethod(did, def::FromImpl(_)) | def::DefMethod(did, _, def::FromImpl(_)) => { callee::trans_fn_ref(bcx, did, ExprId(ref_expr.id)) } - def::DefStaticMethod(impl_did, def::FromTrait(trait_did), _) | + def::DefStaticMethod(impl_did, def::FromTrait(trait_did)) | def::DefMethod(impl_did, _, def::FromTrait(trait_did)) => { meth::trans_static_method_callee(bcx, impl_did, trait_did, ref_expr.id) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 763b55a6fa05c..b9af31665a113 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3626,7 +3626,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { // end (like `UnitStruct`) which means this is an ExprPath to a DefFn. But in case // of unit structs this is should not be interpreted as function pointer but as // call to the constructor. - def::DefFn(_, _, true) => RvalueDpsExpr, + def::DefFn(_, true) => RvalueDpsExpr, // Fn pointers are just scalar values. def::DefFn(..) | def::DefStaticMethod(..) | def::DefMethod(..) => RvalueDatumExpr, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 13ffc1f4fcbaa..f334d8016927d 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -4990,7 +4990,7 @@ pub fn polytype_for_def(fcx: &FnCtxt, let typ = fcx.local_ty(sp, nid); return no_params(typ); } - def::DefFn(id, _, _) | def::DefStaticMethod(id, _, _) | def::DefMethod(id, _, _) | + def::DefFn(id, _) | def::DefStaticMethod(id, _) | def::DefMethod(id, _, _) | def::DefStatic(id, _) | def::DefVariant(_, id, _) | def::DefStruct(id) | def::DefConst(id) => { return ty::lookup_item_type(fcx.ccx.tcx, id);