Skip to content

Commit a34b0a4

Browse files
committed
rustc: replace def::MethodProvenance with ty::ImplOrTraitItemContainer.
1 parent 1fe32ca commit a34b0a4

File tree

17 files changed

+96
-113
lines changed

17 files changed

+96
-113
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,7 @@ fn item_to_def_like(cdata: Cmd, item: rbml::Doc, did: ast::DefId) -> DefLike {
299299
Constant => {
300300
// Check whether we have an associated const item.
301301
if item_sort(item) == Some('C') {
302-
// Check whether the associated const is from a trait or impl.
303-
// See the comment for methods below.
304-
let provenance = if reader::maybe_get_doc(
305-
item, tag_item_trait_parent_sort).is_some() {
306-
def::FromTrait(item_require_parent_item(cdata, item))
307-
} else {
308-
def::FromImpl(item_require_parent_item(cdata, item))
309-
};
310-
DlDef(def::DefAssociatedConst(did, provenance))
302+
DlDef(def::DefAssociatedConst(did))
311303
} else {
312304
// Regular const item.
313305
DlDef(def::DefConst(did))
@@ -319,18 +311,7 @@ fn item_to_def_like(cdata: Cmd, item: rbml::Doc, did: ast::DefId) -> DefLike {
319311
Fn => DlDef(def::DefFn(did, false)),
320312
CtorFn => DlDef(def::DefFn(did, true)),
321313
Method | StaticMethod => {
322-
// def_static_method carries an optional field of its enclosing
323-
// trait or enclosing impl (if this is an inherent static method).
324-
// So we need to detect whether this is in a trait or not, which
325-
// we do through the mildly hacky way of checking whether there is
326-
// a trait_parent_sort.
327-
let provenance = if reader::maybe_get_doc(
328-
item, tag_item_trait_parent_sort).is_some() {
329-
def::FromTrait(item_require_parent_item(cdata, item))
330-
} else {
331-
def::FromImpl(item_require_parent_item(cdata, item))
332-
};
333-
DlDef(def::DefMethod(did, provenance))
314+
DlDef(def::DefMethod(did))
334315
}
335316
Type => {
336317
if item_sort(item) == Some('t') {

src/librustc/middle/astencode.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ impl tr for def::Def {
444444
fn tr(&self, dcx: &DecodeContext) -> def::Def {
445445
match *self {
446446
def::DefFn(did, is_ctor) => def::DefFn(did.tr(dcx), is_ctor),
447-
def::DefMethod(did, p) => {
448-
def::DefMethod(did.tr(dcx), p.map(|did2| did2.tr(dcx)))
449-
}
447+
def::DefMethod(did) => def::DefMethod(did.tr(dcx)),
450448
def::DefSelfTy(opt_did, impl_ids) => { def::DefSelfTy(opt_did.map(|did| did.tr(dcx)),
451449
impl_ids.map(|(nid1, nid2)| {
452450
(dcx.tr_id(nid1),
@@ -456,9 +454,7 @@ impl tr for def::Def {
456454
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(dcx)) }
457455
def::DefStatic(did, m) => { def::DefStatic(did.tr(dcx), m) }
458456
def::DefConst(did) => { def::DefConst(did.tr(dcx)) }
459-
def::DefAssociatedConst(did, p) => {
460-
def::DefAssociatedConst(did.tr(dcx), p.map(|did2| did2.tr(dcx)))
461-
}
457+
def::DefAssociatedConst(did) => def::DefAssociatedConst(did.tr(dcx)),
462458
def::DefLocal(nid) => { def::DefLocal(dcx.tr_id(nid)) }
463459
def::DefVariant(e_did, v_did, is_s) => {
464460
def::DefVariant(e_did.tr(dcx), v_did.tr(dcx), is_s)

src/librustc/middle/check_const.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
650650
}
651651
}
652652
Some(def::DefConst(did)) |
653-
Some(def::DefAssociatedConst(did, _)) => {
653+
Some(def::DefAssociatedConst(did)) => {
654654
if let Some(expr) = const_eval::lookup_const_by_id(v.tcx, did,
655655
Some(e.id)) {
656656
let inner = v.global_expr(Mode::Const, expr);
@@ -696,10 +696,17 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
696696
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
697697
true
698698
}
699-
Some(def::DefMethod(did, def::FromImpl(_))) |
700699
Some(def::DefFn(did, _)) => {
701700
v.handle_const_fn_call(e, did, node_ty)
702701
}
702+
Some(def::DefMethod(did)) => {
703+
match v.tcx.impl_or_trait_item(did).container() {
704+
ty::ImplContainer(_) => {
705+
v.handle_const_fn_call(e, did, node_ty)
706+
}
707+
ty::TraitContainer(_) => false
708+
}
709+
}
703710
_ => false
704711
};
705712
if !is_const {

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
442442
ast::PatIdent(..) | ast::PatEnum(..) | ast::PatQPath(..) => {
443443
let def = self.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def());
444444
match def {
445-
Some(DefAssociatedConst(did, _)) |
445+
Some(DefAssociatedConst(did)) |
446446
Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did, Some(pat.id)) {
447447
Some(const_expr) => {
448448
const_expr_to_pat(self.tcx, const_expr, pat.span).map(|new_pat| {

src/librustc/middle/check_static_recursion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
238238
ast::ExprPath(..) => {
239239
match self.def_map.borrow().get(&e.id).map(|d| d.base_def) {
240240
Some(DefStatic(def_id, _)) |
241-
Some(DefAssociatedConst(def_id, _)) |
241+
Some(DefAssociatedConst(def_id)) |
242242
Some(DefConst(def_id))
243243
if ast_util::is_local(def_id) => {
244244
match self.ast_map.get(def_id.node) {

src/librustc/middle/const_eval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> {
4141
let opt_def = tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
4242
match opt_def {
4343
Some(def::DefConst(def_id)) |
44-
Some(def::DefAssociatedConst(def_id, _)) => {
44+
Some(def::DefAssociatedConst(def_id)) => {
4545
lookup_const_by_id(tcx, def_id, Some(e.id))
4646
}
4747
Some(def::DefVariant(enum_def, variant_def, _)) => {
@@ -929,10 +929,10 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
929929
(lookup_const_by_id(tcx, def_id, Some(e.id)), None)
930930
}
931931
}
932-
Some(def::DefAssociatedConst(def_id, provenance)) => {
932+
Some(def::DefAssociatedConst(def_id)) => {
933933
if ast_util::is_local(def_id) {
934-
match provenance {
935-
def::FromTrait(trait_id) => match tcx.map.find(def_id.node) {
934+
match tcx.impl_or_trait_item(def_id).container() {
935+
ty::TraitContainer(trait_id) => match tcx.map.find(def_id.node) {
936936
Some(ast_map::NodeTraitItem(ti)) => match ti.node {
937937
ast::ConstTraitItem(ref ty, _) => {
938938
if let ExprTypeChecked = ty_hint {
@@ -950,7 +950,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
950950
},
951951
_ => (None, None)
952952
},
953-
def::FromImpl(_) => match tcx.map.find(def_id.node) {
953+
ty::ImplContainer(_) => match tcx.map.find(def_id.node) {
954954
Some(ast_map::NodeImplItem(ii)) => match ii.node {
955955
ast::ConstImplItem(ref ty, ref expr) => {
956956
(Some(&**expr), Some(&**ty))

src/librustc/middle/def.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
pub use self::Def::*;
12-
pub use self::MethodProvenance::*;
1312

1413
use middle::privacy::LastPrivate;
1514
use middle::subst::ParamSpace;
@@ -28,7 +27,7 @@ pub enum Def {
2827
DefForeignMod(ast::DefId),
2928
DefStatic(ast::DefId, bool /* is_mutbl */),
3029
DefConst(ast::DefId),
31-
DefAssociatedConst(ast::DefId /* const */, MethodProvenance),
30+
DefAssociatedConst(ast::DefId),
3231
DefLocal(ast::NodeId),
3332
DefVariant(ast::DefId /* enum */, ast::DefId /* variant */, bool /* is_structure */),
3433
DefTy(ast::DefId, bool /* is_enum */),
@@ -51,7 +50,7 @@ pub enum Def {
5150
DefStruct(ast::DefId),
5251
DefRegion(ast::NodeId),
5352
DefLabel(ast::NodeId),
54-
DefMethod(ast::DefId /* method */, MethodProvenance),
53+
DefMethod(ast::DefId),
5554
}
5655

5756
/// The result of resolving a path.
@@ -112,23 +111,6 @@ pub struct Export {
112111
pub def_id: ast::DefId, // The definition of the target.
113112
}
114113

115-
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
116-
pub enum MethodProvenance {
117-
FromTrait(ast::DefId),
118-
FromImpl(ast::DefId),
119-
}
120-
121-
impl MethodProvenance {
122-
pub fn map<F>(self, f: F) -> MethodProvenance where
123-
F: FnOnce(ast::DefId) -> ast::DefId,
124-
{
125-
match self {
126-
FromTrait(did) => FromTrait(f(did)),
127-
FromImpl(did) => FromImpl(f(did))
128-
}
129-
}
130-
}
131-
132114
impl Def {
133115
pub fn local_node_id(&self) -> ast::NodeId {
134116
let def_id = self.def_id();
@@ -141,7 +123,7 @@ impl Def {
141123
DefFn(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) |
142124
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) |
143125
DefTyParam(_, _, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) |
144-
DefMethod(id, _) | DefConst(id) | DefAssociatedConst(id, _) |
126+
DefMethod(id) | DefConst(id) | DefAssociatedConst(id) |
145127
DefSelfTy(Some(id), None)=> {
146128
id
147129
}

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,12 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
545545

546546
match trait_item.node {
547547
ast::ConstTraitItem(..) => {
548-
let def = DefAssociatedConst(local_def(trait_item.id),
549-
FromTrait(local_def(item.id)));
548+
let def = DefAssociatedConst(local_def(trait_item.id));
550549
// NB: not DefModifiers::IMPORTABLE
551550
name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
552551
}
553552
ast::MethodTraitItem(..) => {
554-
let def = DefMethod(local_def(trait_item.id),
555-
FromTrait(local_def(item.id)));
553+
let def = DefMethod(local_def(trait_item.id));
556554
// NB: not DefModifiers::IMPORTABLE
557555
name_bindings.define_value(def, trait_item.span, DefModifiers::PUBLIC);
558556
}

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
34483448
// Look for a method in the current self type's impl module.
34493449
if let Some(module) = get_module(self, path.span, &name_path) {
34503450
if let Some(binding) = module.children.borrow().get(&name) {
3451-
if let Some(DefMethod(did, _)) = binding.def_for_namespace(ValueNS) {
3451+
if let Some(DefMethod(did)) = binding.def_for_namespace(ValueNS) {
34523452
if is_static_method(self, did) {
34533453
return StaticMethod(path_names_to_string(&path, 0))
34543454
}

src/librustc_trans/save/dump_csv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
719719
let def_map = self.tcx.def_map.borrow();
720720
let def = def_map.get(&id).unwrap().full_def();
721721
match def {
722-
def::DefMethod(did, _) => {
722+
def::DefMethod(did) => {
723723
let ti = self.tcx.impl_or_trait_item(did);
724724
if let ty::MethodTraitItem(m) = ti {
725725
if m.explicit_self == ty::StaticExplicitSelfCategory {

0 commit comments

Comments
 (0)