Skip to content

Commit 2084c2c

Browse files
committed
Rename Def's variants and don't reexport them
1 parent d6c9aa8 commit 2084c2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+581
-577
lines changed

src/librustc/middle/astconv_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Almost certainly this could (and should) be refactored out of existence.
1515
*/
1616

17-
use middle::def;
17+
use middle::def::Def;
1818
use middle::ty::{self, Ty};
1919

2020
use syntax::codemap::Span;
@@ -72,7 +72,7 @@ pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
7272
}
7373
Some(d) => d.full_def()
7474
};
75-
if let def::DefPrimTy(nty) = def {
75+
if let Def::PrimTy(nty) = def {
7676
Some(prim_ty_to_ty(tcx, &path.segments, nty))
7777
} else {
7878
None

src/librustc/middle/cfg/construct.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use rustc_data_structures::graph;
1212
use middle::cfg::*;
13-
use middle::def;
13+
use middle::def::Def;
1414
use middle::pat_util;
1515
use middle::ty;
1616
use syntax::ast;
@@ -591,7 +591,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
591591
}
592592

593593
match self.tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def()) {
594-
Some(def::DefLabel(loop_id)) => {
594+
Some(Def::Label(loop_id)) => {
595595
for l in &self.loop_scopes {
596596
if l.loop_id == loop_id {
597597
return *l;

src/librustc/middle/check_const.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use middle::ty::cast::{CastKind};
2929
use middle::const_eval::{self, ConstEvalErr};
3030
use middle::const_eval::ErrKind::IndexOpFeatureGated;
3131
use middle::const_eval::EvalHint::ExprTypeChecked;
32-
use middle::def;
32+
use middle::def::Def;
3333
use middle::def_id::DefId;
3434
use middle::expr_use_visitor as euv;
3535
use middle::infer;
@@ -610,21 +610,21 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
610610
hir::ExprPath(..) => {
611611
let def = v.tcx.def_map.borrow().get(&e.id).map(|d| d.full_def());
612612
match def {
613-
Some(def::DefVariant(..)) => {
613+
Some(Def::Variant(..)) => {
614614
// Count the discriminator or function pointer.
615615
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
616616
}
617-
Some(def::DefStruct(..)) => {
617+
Some(Def::Struct(..)) => {
618618
if let ty::TyBareFn(..) = node_ty.sty {
619619
// Count the function pointer.
620620
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
621621
}
622622
}
623-
Some(def::DefFn(..)) | Some(def::DefMethod(..)) => {
623+
Some(Def::Fn(..)) | Some(Def::Method(..)) => {
624624
// Count the function pointer.
625625
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
626626
}
627-
Some(def::DefStatic(..)) => {
627+
Some(Def::Static(..)) => {
628628
match v.mode {
629629
Mode::Static | Mode::StaticMut => {}
630630
Mode::Const | Mode::ConstFn => {
@@ -635,16 +635,16 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
635635
Mode::Var => v.add_qualif(ConstQualif::NOT_CONST)
636636
}
637637
}
638-
Some(def::DefConst(did)) |
639-
Some(def::DefAssociatedConst(did)) => {
638+
Some(Def::Const(did)) |
639+
Some(Def::AssociatedConst(did)) => {
640640
if let Some(expr) = const_eval::lookup_const_by_id(v.tcx, did,
641641
Some(e.id),
642642
None) {
643643
let inner = v.global_expr(Mode::Const, expr);
644644
v.add_qualif(inner);
645645
}
646646
}
647-
Some(def::DefLocal(..)) if v.mode == Mode::ConstFn => {
647+
Some(Def::Local(..)) if v.mode == Mode::ConstFn => {
648648
// Sadly, we can't determine whether the types are zero-sized.
649649
v.add_qualif(ConstQualif::NOT_CONST | ConstQualif::NON_ZERO_SIZED);
650650
}
@@ -672,16 +672,16 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
672672
}
673673
let def = v.tcx.def_map.borrow().get(&callee.id).map(|d| d.full_def());
674674
let is_const = match def {
675-
Some(def::DefStruct(..)) => true,
676-
Some(def::DefVariant(..)) => {
675+
Some(Def::Struct(..)) => true,
676+
Some(Def::Variant(..)) => {
677677
// Count the discriminator.
678678
v.add_qualif(ConstQualif::NON_ZERO_SIZED);
679679
true
680680
}
681-
Some(def::DefFn(did)) => {
681+
Some(Def::Fn(did)) => {
682682
v.handle_const_fn_call(e, did, node_ty)
683683
}
684-
Some(def::DefMethod(did)) => {
684+
Some(Def::Method(did)) => {
685685
match v.tcx.impl_or_trait_item(did).container() {
686686
ty::ImplContainer(_) => {
687687
v.handle_const_fn_call(e, did, node_ty)

src/librustc/middle/check_match.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
246246
let pat_ty = cx.tcx.pat_ty(p);
247247
if let ty::TyEnum(edef, _) = pat_ty.sty {
248248
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
249-
if let Some(DefLocal(..)) = def {
249+
if let Some(Def::Local(..)) = def {
250250
if edef.variants.iter().any(|variant|
251251
variant.name == ident.node.unhygienic_name
252252
&& variant.kind() == VariantKind::Unit
@@ -454,8 +454,8 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
454454
hir::PatIdent(..) | hir::PatEnum(..) | hir::PatQPath(..) => {
455455
let def = self.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def());
456456
match def {
457-
Some(DefAssociatedConst(did)) |
458-
Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did,
457+
Some(Def::AssociatedConst(did)) |
458+
Some(Def::Const(did)) => match lookup_const_by_id(self.tcx, did,
459459
Some(pat.id), None) {
460460
Some(const_expr) => {
461461
const_expr_to_pat(self.tcx, const_expr, pat.span).map(|new_pat| {
@@ -757,30 +757,30 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
757757
match pat.node {
758758
hir::PatIdent(..) =>
759759
match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
760-
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
760+
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
761761
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
762762
been rewritten"),
763-
Some(DefStruct(..)) => vec!(Single),
764-
Some(DefVariant(_, id)) => vec!(Variant(id)),
763+
Some(Def::Struct(..)) => vec!(Single),
764+
Some(Def::Variant(_, id)) => vec!(Variant(id)),
765765
_ => vec!()
766766
},
767767
hir::PatEnum(..) =>
768768
match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
769-
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
769+
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
770770
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
771771
been rewritten"),
772-
Some(DefVariant(_, id)) => vec!(Variant(id)),
772+
Some(Def::Variant(_, id)) => vec!(Variant(id)),
773773
_ => vec!(Single)
774774
},
775775
hir::PatQPath(..) =>
776776
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
777777
been rewritten"),
778778
hir::PatStruct(..) =>
779779
match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
780-
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
780+
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
781781
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
782782
been rewritten"),
783-
Some(DefVariant(_, id)) => vec!(Variant(id)),
783+
Some(Def::Variant(_, id)) => vec!(Variant(id)),
784784
_ => vec!(Single)
785785
},
786786
hir::PatLit(ref expr) =>
@@ -869,10 +869,10 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
869869
hir::PatIdent(_, _, _) => {
870870
let opt_def = cx.tcx.def_map.borrow().get(&pat_id).map(|d| d.full_def());
871871
match opt_def {
872-
Some(DefConst(..)) | Some(DefAssociatedConst(..)) =>
872+
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
873873
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
874874
been rewritten"),
875-
Some(DefVariant(_, id)) => if *constructor == Variant(id) {
875+
Some(Def::Variant(_, id)) => if *constructor == Variant(id) {
876876
Some(vec!())
877877
} else {
878878
None
@@ -884,11 +884,11 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
884884
hir::PatEnum(_, ref args) => {
885885
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
886886
match def {
887-
DefConst(..) | DefAssociatedConst(..) =>
887+
Def::Const(..) | Def::AssociatedConst(..) =>
888888
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
889889
been rewritten"),
890-
DefVariant(_, id) if *constructor != Variant(id) => None,
891-
DefVariant(..) | DefStruct(..) => {
890+
Def::Variant(_, id) if *constructor != Variant(id) => None,
891+
Def::Variant(..) | Def::Struct(..) => {
892892
Some(match args {
893893
&Some(ref args) => args.iter().map(|p| &**p).collect(),
894894
&None => vec![DUMMY_WILD_PAT; arity],

src/librustc/middle/check_static_recursion.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use front::map as ast_map;
1515
use session::Session;
16-
use middle::def::{DefStatic, DefConst, DefAssociatedConst, DefVariant, DefMap};
16+
use middle::def::{Def, DefMap};
1717
use util::nodemap::NodeMap;
1818

1919
use syntax::{ast};
@@ -238,9 +238,9 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
238238
match e.node {
239239
hir::ExprPath(..) => {
240240
match self.def_map.get(&e.id).map(|d| d.base_def) {
241-
Some(DefStatic(def_id, _)) |
242-
Some(DefAssociatedConst(def_id)) |
243-
Some(DefConst(def_id)) => {
241+
Some(Def::Static(def_id, _)) |
242+
Some(Def::AssociatedConst(def_id)) |
243+
Some(Def::Const(def_id)) => {
244244
if let Some(node_id) = self.ast_map.as_local_node_id(def_id) {
245245
match self.ast_map.get(node_id) {
246246
ast_map::NodeItem(item) =>
@@ -263,7 +263,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
263263
// affect the specific variant used, but we need to check
264264
// the whole enum definition to see what expression that
265265
// might be (if any).
266-
Some(DefVariant(enum_id, variant_id)) => {
266+
Some(Def::Variant(enum_id, variant_id)) => {
267267
if let Some(enum_node_id) = self.ast_map.as_local_node_id(enum_id) {
268268
if let hir::ItemEnum(ref enum_def, ref generics) =
269269
self.ast_map.expect_item(enum_node_id).node
@@ -276,7 +276,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
276276
} else {
277277
self.sess.span_bug(e.span,
278278
"`check_static_recursion` found \
279-
non-enum in DefVariant");
279+
non-enum in Def::Variant");
280280
}
281281
}
282282
}

src/librustc/middle/const_eval.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use self::EvalHint::*;
1717
use front::map as ast_map;
1818
use front::map::blocks::FnLikeNode;
1919
use middle::cstore::{self, CrateStore, InlinedItem};
20-
use middle::{def, infer, subst, traits};
20+
use middle::{infer, subst, traits};
21+
use middle::def::Def;
2122
use middle::subst::Subst;
2223
use middle::def_id::DefId;
2324
use middle::pat_util::def_to_path;
@@ -331,9 +332,9 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
331332
entry.insert(def);
332333
}
333334
let path = match def.full_def() {
334-
def::DefStruct(def_id) => def_to_path(tcx, def_id),
335-
def::DefVariant(_, variant_did) => def_to_path(tcx, variant_did),
336-
def::DefFn(..) => return P(hir::Pat {
335+
Def::Struct(def_id) => def_to_path(tcx, def_id),
336+
Def::Variant(_, variant_did) => def_to_path(tcx, variant_did),
337+
Def::Fn(..) => return P(hir::Pat {
337338
id: expr.id,
338339
node: hir::PatLit(P(expr.clone())),
339340
span: span,
@@ -364,12 +365,12 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
364365
hir::ExprPath(_, ref path) => {
365366
let opt_def = tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def());
366367
match opt_def {
367-
Some(def::DefStruct(..)) =>
368+
Some(Def::Struct(..)) =>
368369
hir::PatStruct(path.clone(), hir::HirVec::new(), false),
369-
Some(def::DefVariant(..)) =>
370+
Some(Def::Variant(..)) =>
370371
hir::PatEnum(path.clone(), None),
371-
Some(def::DefConst(def_id)) |
372-
Some(def::DefAssociatedConst(def_id)) => {
372+
Some(Def::Const(def_id)) |
373+
Some(Def::AssociatedConst(def_id)) => {
373374
let expr = lookup_const_by_id(tcx, def_id, Some(expr.id), None).unwrap();
374375
return const_expr_to_pat(tcx, expr, span);
375376
},
@@ -1002,7 +1003,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10021003
None
10031004
};
10041005
let (const_expr, const_ty) = match opt_def {
1005-
Some(def::DefConst(def_id)) => {
1006+
Some(Def::Const(def_id)) => {
10061007
if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
10071008
match tcx.map.find(node_id) {
10081009
Some(ast_map::NodeItem(it)) => match it.node {
@@ -1017,7 +1018,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10171018
(lookup_const_by_id(tcx, def_id, Some(e.id), None), None)
10181019
}
10191020
}
1020-
Some(def::DefAssociatedConst(def_id)) => {
1021+
Some(Def::AssociatedConst(def_id)) => {
10211022
if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
10221023
match tcx.impl_or_trait_item(def_id).container() {
10231024
ty::TraitContainer(trait_id) => match tcx.map.find(node_id) {
@@ -1052,21 +1053,21 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10521053
(lookup_const_by_id(tcx, def_id, Some(e.id), None), None)
10531054
}
10541055
}
1055-
Some(def::DefVariant(enum_def, variant_def)) => {
1056+
Some(Def::Variant(enum_def, variant_def)) => {
10561057
(lookup_variant_by_id(tcx, enum_def, variant_def), None)
10571058
}
1058-
Some(def::DefStruct(..)) => {
1059+
Some(Def::Struct(..)) => {
10591060
return Ok(ConstVal::Struct(e.id))
10601061
}
1061-
Some(def::DefLocal(_, id)) => {
1062-
debug!("DefLocal({:?}): {:?}", id, fn_args);
1062+
Some(Def::Local(_, id)) => {
1063+
debug!("Def::Local({:?}): {:?}", id, fn_args);
10631064
if let Some(val) = fn_args.and_then(|args| args.get(&id)) {
10641065
return Ok(val.clone());
10651066
} else {
10661067
(None, None)
10671068
}
10681069
},
1069-
Some(def::DefMethod(id)) | Some(def::DefFn(id)) => return Ok(Function(id)),
1070+
Some(Def::Method(id)) | Some(Def::Fn(id)) => return Ok(Function(id)),
10701071
_ => (None, None)
10711072
};
10721073
let const_expr = match const_expr {

src/librustc/middle/cstore.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
use back::svh::Svh;
2626
use front::map as hir_map;
27-
use middle::def;
27+
use middle::def::{self, Def};
2828
use middle::lang_items;
2929
use middle::ty::{self, Ty, VariantKind};
3030
use middle::def_id::{DefId, DefIndex};
@@ -84,7 +84,7 @@ enum_from_u32! {
8484
// Something that a name can resolve to.
8585
#[derive(Copy, Clone, Debug)]
8686
pub enum DefLike {
87-
DlDef(def::Def),
87+
DlDef(Def),
8888
DlImpl(DefId),
8989
DlField
9090
}

src/librustc/middle/dead.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use front::map as ast_map;
1717
use rustc_front::hir;
1818
use rustc_front::intravisit::{self, Visitor};
1919

20-
use middle::{def, pat_util, privacy, ty};
20+
use middle::{pat_util, privacy, ty};
21+
use middle::def::Def;
2122
use middle::def_id::{DefId};
2223
use lint;
2324

@@ -94,13 +95,13 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9495

9596
self.tcx.def_map.borrow().get(id).map(|def| {
9697
match def.full_def() {
97-
def::DefConst(_) | def::DefAssociatedConst(..) => {
98+
Def::Const(_) | Def::AssociatedConst(..) => {
9899
self.check_def_id(def.def_id());
99100
}
100101
_ if self.ignore_non_const_paths => (),
101-
def::DefPrimTy(_) => (),
102-
def::DefSelfTy(..) => (),
103-
def::DefVariant(enum_id, variant_id) => {
102+
Def::PrimTy(_) => (),
103+
Def::SelfTy(..) => (),
104+
Def::Variant(enum_id, variant_id) => {
104105
self.check_def_id(enum_id);
105106
if !self.ignore_variant_stack.contains(&variant_id) {
106107
self.check_def_id(variant_id);

0 commit comments

Comments
 (0)