Skip to content

Commit ebdaa8e

Browse files
committed
rustc_resolve: remove the distinction between DefStaticMethod and DefMethod.
1 parent a13c70c commit ebdaa8e

File tree

16 files changed

+89
-158
lines changed

16 files changed

+89
-158
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,9 @@ pub fn get_trait_name(cstore: &cstore::CStore, def: ast::DefId) -> ast::Name {
150150
def.node)
151151
}
152152

153-
pub fn get_trait_item_name_and_kind(cstore: &cstore::CStore, def: ast::DefId)
154-
-> (ast::Name, def::TraitItemKind) {
153+
pub fn is_static_method(cstore: &cstore::CStore, def: ast::DefId) -> bool {
155154
let cdata = cstore.get_crate_data(def.krate);
156-
decoder::get_trait_item_name_and_kind(cstore.intr.clone(),
157-
&*cdata,
158-
def.node)
155+
decoder::is_static_method(&*cdata, def.node)
159156
}
160157

161158
pub fn get_trait_item_def_ids(cstore: &cstore::CStore, def: ast::DefId)

src/librustc/metadata/decoder.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,7 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
332332
def::FromImpl(item_reqd_and_translated_parent_item(cnum,
333333
item))
334334
};
335-
match fam {
336-
// We don't bother to get encode/decode the trait id, we don't need it.
337-
Method => DlDef(def::DefMethod(did, None, provenance)),
338-
StaticMethod => DlDef(def::DefStaticMethod(did, provenance)),
339-
_ => panic!()
340-
}
335+
DlDef(def::DefMethod(did, provenance))
341336
}
342337
Type => {
343338
if item_sort(item) == Some('t') {
@@ -845,22 +840,13 @@ pub fn get_trait_name(intr: Rc<IdentInterner>,
845840
item_name(&*intr, doc)
846841
}
847842

848-
pub fn get_trait_item_name_and_kind(intr: Rc<IdentInterner>,
849-
cdata: Cmd,
850-
id: ast::NodeId)
851-
-> (ast::Name, def::TraitItemKind) {
843+
pub fn is_static_method(cdata: Cmd, id: ast::NodeId) -> bool {
852844
let doc = lookup_item(id, cdata.data());
853-
let name = item_name(&*intr, doc);
854845
match item_sort(doc) {
855846
Some('r') | Some('p') => {
856-
let explicit_self = get_explicit_self(doc);
857-
(name, def::TraitItemKind::from_explicit_self_category(explicit_self))
858-
}
859-
Some('t') => (name, def::TypeTraitItemKind),
860-
c => {
861-
panic!("get_trait_item_name_and_kind(): unknown trait item kind \
862-
in metadata: `{:?}`", c)
847+
get_explicit_self(doc) == ty::StaticExplicitSelfCategory
863848
}
849+
_ => false
864850
}
865851
}
866852

src/librustc/middle/astencode.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,8 @@ impl tr for def::Def {
421421
fn tr(&self, dcx: &DecodeContext) -> def::Def {
422422
match *self {
423423
def::DefFn(did, is_ctor) => def::DefFn(did.tr(dcx), is_ctor),
424-
def::DefStaticMethod(did, p) => {
425-
def::DefStaticMethod(did.tr(dcx), p.map(|did2| did2.tr(dcx)))
426-
}
427-
def::DefMethod(did0, did1, p) => {
428-
def::DefMethod(did0.tr(dcx),
429-
did1.map(|did1| did1.tr(dcx)),
430-
p.map(|did2| did2.tr(dcx)))
424+
def::DefMethod(did, p) => {
425+
def::DefMethod(did.tr(dcx), p.map(|did2| did2.tr(dcx)))
431426
}
432427
def::DefSelfTy(nid) => { def::DefSelfTy(dcx.tr_id(nid)) }
433428
def::DefMod(did) => { def::DefMod(did.tr(dcx)) }

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) {
114114
ast::ExprPath(_) | ast::ExprQPath(_) => {
115115
match v.tcx.def_map.borrow()[e.id] {
116116
DefStatic(..) | DefConst(..) |
117-
DefFn(..) | DefStaticMethod(..) | DefMethod(..) |
117+
DefFn(..) | DefMethod(..) |
118118
DefStruct(_) | DefVariant(_, _, _) => {}
119119

120120
def => {

src/librustc/middle/def.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010

1111
pub use self::Def::*;
1212
pub use self::MethodProvenance::*;
13-
pub use self::TraitItemKind::*;
1413

1514
use middle::subst::ParamSpace;
16-
use middle::ty::{ExplicitSelfCategory, StaticExplicitSelfCategory};
1715
use util::nodemap::NodeMap;
1816
use syntax::ast;
1917
use syntax::ast_util::local_def;
@@ -23,7 +21,6 @@ use std::cell::RefCell;
2321
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
2422
pub enum Def {
2523
DefFn(ast::DefId, bool /* is_ctor */),
26-
DefStaticMethod(/* method */ ast::DefId, MethodProvenance),
2724
DefSelfTy(/* trait id */ ast::NodeId),
2825
DefMod(ast::DefId),
2926
DefForeignMod(ast::DefId),
@@ -51,7 +48,7 @@ pub enum Def {
5148
DefStruct(ast::DefId),
5249
DefRegion(ast::NodeId),
5350
DefLabel(ast::NodeId),
54-
DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */, MethodProvenance),
51+
DefMethod(ast::DefId /* method */, MethodProvenance),
5552
}
5653

5754
/// The result of resolving the prefix of a path to a type:
@@ -99,25 +96,6 @@ impl MethodProvenance {
9996
}
10097
}
10198

102-
#[derive(Clone, Copy, Eq, PartialEq)]
103-
pub enum TraitItemKind {
104-
NonstaticMethodTraitItemKind,
105-
StaticMethodTraitItemKind,
106-
TypeTraitItemKind,
107-
}
108-
109-
impl TraitItemKind {
110-
pub fn from_explicit_self_category(explicit_self_category:
111-
ExplicitSelfCategory)
112-
-> TraitItemKind {
113-
if explicit_self_category == StaticExplicitSelfCategory {
114-
StaticMethodTraitItemKind
115-
} else {
116-
NonstaticMethodTraitItemKind
117-
}
118-
}
119-
}
120-
12199
impl Def {
122100
pub fn local_node_id(&self) -> ast::NodeId {
123101
let def_id = self.def_id();
@@ -127,11 +105,10 @@ impl Def {
127105

128106
pub fn def_id(&self) -> ast::DefId {
129107
match *self {
130-
DefFn(id, _) | DefStaticMethod(id, _) | DefMod(id) |
131-
DefForeignMod(id) | DefStatic(id, _) |
108+
DefFn(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) |
132109
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) |
133110
DefTyParam(_, _, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) |
134-
DefMethod(id, _, _) | DefConst(id) => {
111+
DefMethod(id, _) | DefConst(id) => {
135112
id
136113
}
137114
DefLocal(id) |

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
575575

576576
match def {
577577
def::DefStruct(..) | def::DefVariant(..) | def::DefConst(..) |
578-
def::DefFn(..) | def::DefStaticMethod(..) | def::DefMethod(..) => {
578+
def::DefFn(..) | def::DefMethod(..) => {
579579
Ok(self.cat_rvalue_node(id, span, expr_ty))
580580
}
581581
def::DefMod(_) | def::DefForeignMod(_) | def::DefUse(_) |

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4504,7 +4504,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
45044504
def::DefFn(_, true) => RvalueDpsExpr,
45054505

45064506
// Fn pointers are just scalar values.
4507-
def::DefFn(..) | def::DefStaticMethod(..) | def::DefMethod(..) => RvalueDatumExpr,
4507+
def::DefFn(..) | def::DefMethod(..) => RvalueDatumExpr,
45084508

45094509
// Note: there is actually a good case to be made that
45104510
// DefArg's, particularly those of immediate type, ought to

src/librustc_privacy/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
795795
// be accurate and we can get slightly wonky error messages (but type
796796
// checking is always correct).
797797
match self.tcx.def_map.borrow()[path_id].clone() {
798-
def::DefStaticMethod(..) => ck("static method"),
799798
def::DefFn(..) => ck("function"),
800799
def::DefStatic(..) => ck("static"),
801800
def::DefConst(..) => ck("const"),
@@ -804,7 +803,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
804803
def::DefTy(_, true) => ck("enum"),
805804
def::DefTrait(..) => ck("trait"),
806805
def::DefStruct(..) => ck("struct"),
807-
def::DefMethod(_, Some(..), _) => ck("trait method"),
808806
def::DefMethod(..) => ck("method"),
809807
def::DefMod(..) => ck("module"),
810808
_ => {}

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ use syntax::ast::{Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn};
4040
use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic};
4141
use syntax::ast::{ItemStruct, ItemTrait, ItemTy, ItemUse};
4242
use syntax::ast::{MethodImplItem, Name, NamedField, NodeId};
43-
use syntax::ast::{PathListIdent, PathListMod};
44-
use syntax::ast::{Public, SelfStatic};
43+
use syntax::ast::{PathListIdent, PathListMod, Public};
4544
use syntax::ast::StmtDecl;
4645
use syntax::ast::StructVariantKind;
4746
use syntax::ast::TupleVariantKind;
@@ -598,22 +597,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
598597
&new_parent,
599598
ForbidDuplicateValues,
600599
method.span);
601-
let def = match method.pe_explicit_self()
602-
.node {
603-
SelfStatic => {
604-
// Static methods become
605-
// `DefStaticMethod`s.
606-
DefStaticMethod(local_def(method.id),
607-
FromImpl(local_def(item.id)))
608-
}
609-
_ => {
610-
// Non-static methods become
611-
// `DefMethod`s.
612-
DefMethod(local_def(method.id),
613-
None,
614-
FromImpl(local_def(item.id)))
615-
}
616-
};
600+
let def = DefMethod(local_def(method.id),
601+
FromImpl(local_def(item.id)));
617602

618603
// NB: not IMPORTABLE
619604
let modifiers = if method.pe_vis() == ast::Public {
@@ -673,31 +658,16 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
673658

674659
// Add the names of all the items to the trait info.
675660
for trait_item in items {
676-
let (name, kind) = match *trait_item {
661+
let (name, trait_item_id) = match *trait_item {
677662
ast::RequiredMethod(_) |
678663
ast::ProvidedMethod(_) => {
679664
let ty_m = ast_util::trait_item_to_ty_method(trait_item);
680665

681666
let name = ty_m.ident.name;
682667

683668
// Add it as a name in the trait module.
684-
let (def, static_flag) = match ty_m.explicit_self
685-
.node {
686-
SelfStatic => {
687-
// Static methods become `DefStaticMethod`s.
688-
(DefStaticMethod(
689-
local_def(ty_m.id),
690-
FromTrait(local_def(item.id))),
691-
StaticMethodTraitItemKind)
692-
}
693-
_ => {
694-
// Non-static methods become `DefMethod`s.
695-
(DefMethod(local_def(ty_m.id),
696-
Some(local_def(item.id)),
697-
FromTrait(local_def(item.id))),
698-
NonstaticMethodTraitItemKind)
699-
}
700-
};
669+
let def = DefMethod(local_def(ty_m.id),
670+
FromTrait(local_def(item.id)));
701671

702672
let method_name_bindings =
703673
self.add_child(name,
@@ -709,7 +679,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
709679
ty_m.span,
710680
PUBLIC);
711681

712-
(name, static_flag)
682+
(name, local_def(ty_m.id))
713683
}
714684
ast::TypeTraitItem(ref associated_type) => {
715685
let def = DefAssociatedTy(local_def(item.id),
@@ -725,11 +695,12 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
725695
associated_type.ty_param.span,
726696
PUBLIC);
727697

728-
(associated_type.ty_param.ident.name, TypeTraitItemKind)
698+
(associated_type.ty_param.ident.name,
699+
local_def(associated_type.ty_param.id))
729700
}
730701
};
731702

732-
self.trait_item_map.insert((name, def_id), kind);
703+
self.trait_item_map.insert((name, def_id), trait_item_id);
733704
}
734705

735706
name_bindings.define_type(DefTrait(def_id), sp, modifiers);
@@ -888,7 +859,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
888859
csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
889860
.map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, modifiers);
890861
}
891-
DefFn(..) | DefStaticMethod(..) | DefStatic(..) | DefConst(..) | DefMethod(..) => {
862+
DefFn(..) | DefStatic(..) | DefConst(..) | DefMethod(..) => {
892863
debug!("(building reduced graph for external \
893864
crate) building value (fn/static) {}", final_ident);
894865
// impl methods have already been defined with the correct importability modifier
@@ -910,21 +881,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
910881

911882
let trait_item_def_ids =
912883
csearch::get_trait_item_def_ids(&self.session.cstore, def_id);
913-
for trait_item_def_id in &trait_item_def_ids {
914-
let (trait_item_name, trait_item_kind) =
915-
csearch::get_trait_item_name_and_kind(
916-
&self.session.cstore,
917-
trait_item_def_id.def_id());
884+
for trait_item_def in &trait_item_def_ids {
885+
let trait_item_name = csearch::get_trait_name(&self.session.cstore,
886+
trait_item_def.def_id());
918887

919888
debug!("(building reduced graph for external crate) ... \
920889
adding trait item '{}'",
921890
token::get_name(trait_item_name));
922891

923-
self.trait_item_map.insert((trait_item_name, def_id), trait_item_kind);
892+
self.trait_item_map.insert((trait_item_name, def_id),
893+
trait_item_def.def_id());
924894

925895
if is_exported {
926-
self.external_exports
927-
.insert(trait_item_def_id.def_id());
896+
self.external_exports.insert(trait_item_def.def_id());
928897
}
929898
}
930899

0 commit comments

Comments
 (0)