Skip to content

Commit

Permalink
Re-order fields in Def::Ctor.
Browse files Browse the repository at this point in the history
This commit moves the `DefId` field of `Def::Ctor` to be the first
field.
  • Loading branch information
davidtwco committed Mar 24, 2019
1 parent 88f8f07 commit 23cae1d
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 39 deletions.
16 changes: 8 additions & 8 deletions src/librustc/hir/def.rs
Expand Up @@ -73,7 +73,7 @@ pub enum Def {
ConstParam(DefId),
Static(DefId, bool /* is_mutbl */),
/// `DefId` refers to the struct or enum variant's constructor.
Ctor(CtorOf, DefId, CtorKind),
Ctor(DefId, CtorOf, CtorKind),
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
Method(DefId),
AssociatedConst(DefId),
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Def {
pub fn opt_def_id(&self) -> Option<DefId> {
match *self {
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
Def::Variant(id) | Def::Ctor(_, id, ..) | Def::Enum(id) |
Def::Variant(id) | Def::Ctor(id, ..) | Def::Enum(id) |
Def::TyAlias(id) | Def::TraitAlias(id) |
Def::AssociatedTy(id) | Def::TyParam(id) | Def::ConstParam(id) | Def::Struct(id) |
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
Expand Down Expand Up @@ -315,13 +315,13 @@ impl Def {
Def::Static(..) => "static",
Def::Enum(..) => "enum",
Def::Variant(..) => "variant",
Def::Ctor(CtorOf::Variant, _, CtorKind::Fn) => "tuple variant",
Def::Ctor(CtorOf::Variant, _, CtorKind::Const) => "unit variant",
Def::Ctor(CtorOf::Variant, _, CtorKind::Fictive) => "struct variant",
Def::Ctor(_, CtorOf::Variant, CtorKind::Fn) => "tuple variant",
Def::Ctor(_, CtorOf::Variant, CtorKind::Const) => "unit variant",
Def::Ctor(_, CtorOf::Variant, CtorKind::Fictive) => "struct variant",
Def::Struct(..) => "struct",
Def::Ctor(CtorOf::Struct, _, CtorKind::Fn) => "tuple struct",
Def::Ctor(CtorOf::Struct, _, CtorKind::Const) => "unit struct",
Def::Ctor(CtorOf::Struct, _, CtorKind::Fictive) =>
Def::Ctor(_, CtorOf::Struct, CtorKind::Fn) => "tuple struct",
Def::Ctor(_, CtorOf::Struct, CtorKind::Const) => "unit struct",
Def::Ctor(_, CtorOf::Struct, CtorKind::Fictive) =>
bug!("impossible struct constructor"),
Def::Existential(..) => "existential type",
Def::TyAlias(..) => "type alias",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Expand Up @@ -377,7 +377,7 @@ impl<'hir> Map<'hir> {
};
variant_data.ctor_hir_id()
.map(|hir_id| self.local_def_id_from_hir_id(hir_id))
.map(|def_id| Def::Ctor(ctor_of, def_id, def::CtorKind::from_hir(variant_data)))
.map(|def_id| Def::Ctor(def_id, ctor_of, def::CtorKind::from_hir(variant_data)))
}
Node::AnonConst(_) |
Node::Field(_) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/pat_util.rs
Expand Up @@ -126,7 +126,7 @@ impl hir::Pat {
PatKind::Struct(hir::QPath::Resolved(_, ref path), ..) => {
match path.def {
Def::Variant(id) => variants.push(id),
Def::Ctor(CtorOf::Variant, id, _) => variants.push(id),
Def::Ctor(id, CtorOf::Variant, ..) => variants.push(id),
_ => ()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -76,7 +76,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
_ if self.in_pat => (),
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
Def::Local(..) | Def::Upvar(..) => {}
Def::Ctor(CtorOf::Variant, ctor_def_id, ..) => {
Def::Ctor(ctor_def_id, CtorOf::Variant, ..) => {
let variant_id = self.tcx.parent(ctor_def_id).unwrap();
let enum_id = self.tcx.parent(variant_id).unwrap();
self.check_def_id(enum_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -902,7 +902,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
};
let def = mc.tables.qpath_def(qpath, pat.hir_id);
match def {
Def::Ctor(CtorOf::Variant, variant_ctor_did, ..) => {
Def::Ctor(variant_ctor_did, CtorOf::Variant, ..) => {
let variant_did = mc.tcx.parent(variant_ctor_did).unwrap();
let downcast_cmt = mc.cat_downcast_if_needed(pat, cmt_pat, variant_did);

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -1274,14 +1274,14 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
debug!("access to unresolvable pattern {:?}", pat);
return Err(())
}
Def::Ctor(CtorOf::Variant, variant_ctor_did, CtorKind::Fn) => {
Def::Ctor(variant_ctor_did, CtorOf::Variant, CtorKind::Fn) => {
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
let enum_did = self.tcx.parent(variant_did).unwrap();
(self.cat_downcast_if_needed(pat, cmt, variant_did),
self.tcx.adt_def(enum_did)
.variant_with_ctor_id(variant_ctor_did).fields.len())
}
Def::Ctor(CtorOf::Struct, _, CtorKind::Fn) | Def::SelfCtor(..) => {
Def::Ctor(_, CtorOf::Struct, CtorKind::Fn) | Def::SelfCtor(..) => {
let ty = self.pat_ty_unadjusted(&pat)?;
match ty.sty {
ty::Adt(adt_def, _) => {
Expand Down Expand Up @@ -1316,7 +1316,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
debug!("access to unresolvable pattern {:?}", pat);
return Err(())
}
Def::Ctor(CtorOf::Variant, variant_ctor_did, _) => {
Def::Ctor(variant_ctor_did, CtorOf::Variant, _) => {
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
self.cat_downcast_if_needed(pat, cmt, variant_did)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/mod.rs
Expand Up @@ -2322,7 +2322,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
pub fn variant_of_def(&self, def: Def) -> &VariantDef {
match def {
Def::Variant(vid) => self.variant_with_id(vid),
Def::Ctor(_, cid, ..) => self.variant_with_ctor_id(cid),
Def::Ctor(cid, ..) => self.variant_with_ctor_id(cid),
Def::Struct(..) | Def::Union(..) |
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) |
Def::SelfCtor(..) => self.non_enum_variant(),
Expand Down Expand Up @@ -2941,12 +2941,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
Def::Struct(did) | Def::Union(did) => {
self.adt_def(did).non_enum_variant()
}
Def::Ctor(CtorOf::Variant, variant_ctor_did, ..) => {
Def::Ctor(variant_ctor_did, CtorOf::Variant, ..) => {
let variant_did = self.parent(variant_ctor_did).unwrap();
let enum_did = self.parent(variant_did).unwrap();
self.adt_def(enum_did).variant_with_ctor_id(variant_ctor_did)
}
Def::Ctor(CtorOf::Struct, ctor_did, ..) => {
Def::Ctor(ctor_did, CtorOf::Struct, ..) => {
let struct_did = self.parent(ctor_did).expect("struct ctor has no parent");
self.adt_def(struct_did).non_enum_variant()
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -816,8 +816,7 @@ impl<'a, 'tcx> CrateMetadata {
Def::Struct(..) => {
if let Some(ctor_def_id) = self.get_ctor_def_id(child_index) {
let ctor_kind = self.get_ctor_kind(child_index);
let ctor_def = Def::Ctor(
hir::def::CtorOf::Struct, ctor_def_id, ctor_kind);
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Struct, ctor_kind);
let vis = self.get_visibility(ctor_def_id.index);
callback(def::Export { def: ctor_def, vis, ident, span });
}
Expand All @@ -829,7 +828,7 @@ impl<'a, 'tcx> CrateMetadata {
// error will be reported on any use of such resolution anyway.
let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
let ctor_kind = self.get_ctor_kind(child_index);
let ctor_def = Def::Ctor(CtorOf::Variant, ctor_def_id, ctor_kind);
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
let vis = self.get_visibility(ctor_def_id.index);
callback(def::Export { def: ctor_def, ident, vis, span });
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -261,7 +261,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
expr_ty.ty_adt_def().and_then(|adt_def| {
match path.def {
Def::Ctor(_, ctor_id, CtorKind::Fn) =>
Def::Ctor(ctor_id, _, CtorKind::Fn) =>
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id))),
Def::SelfCtor(..) => Some((adt_def, VariantIdx::new(0))),
_ => None,
Expand Down Expand Up @@ -675,7 +675,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
.ty_adt_def()
.and_then(|adt_def| {
match def {
Def::Ctor(CtorOf::Variant, variant_ctor_id, CtorKind::Const) => {
Def::Ctor(variant_ctor_id, CtorOf::Variant, CtorKind::Const) => {
let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
let (d, o) = adt_def.discriminant_def_for_variant(idx);
use rustc::ty::util::IntTypeExt;
Expand Down Expand Up @@ -951,7 +951,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
}
},

Def::Ctor(_, def_id, CtorKind::Const) => {
Def::Ctor(def_id, _, CtorKind::Const) => {
let user_provided_types = cx.tables.user_provided_types();
let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/hair/pattern/mod.rs
Expand Up @@ -734,7 +734,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
subpatterns: Vec<FieldPattern<'tcx>>,
) -> PatternKind<'tcx> {
let def = match def {
Def::Ctor(CtorOf::Variant, variant_ctor_id, ..) => {
Def::Ctor(variant_ctor_id, CtorOf::Variant, ..) => {
let variant_id = self.tcx.parent(variant_ctor_id).unwrap();
Def::Variant(variant_id)
},
Expand Down Expand Up @@ -765,7 +765,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
}
}

Def::Struct(..) | Def::Ctor(CtorOf::Struct, ..) | Def::Union(..) |
Def::Struct(..) | Def::Ctor(_, CtorOf::Struct, ..) | Def::Union(..) |
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) => {
PatternKind::Leaf { subpatterns }
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -533,8 +533,8 @@ impl<'a> Resolver<'a> {
// If this is a tuple or unit struct, define a name
// in the value namespace as well.
if let Some(ctor_node_id) = struct_def.ctor_id() {
let ctor_def = Def::Ctor(CtorOf::Struct,
self.definitions.local_def_id(ctor_node_id),
let ctor_def = Def::Ctor(self.definitions.local_def_id(ctor_node_id),
CtorOf::Struct,
CtorKind::from_ast(struct_def));
self.define(parent, ident, ValueNS, (ctor_def, ctor_vis, sp, expansion));
self.struct_constructors.insert(def.def_id(), (ctor_def, ctor_vis));
Expand Down Expand Up @@ -596,7 +596,7 @@ impl<'a> Resolver<'a> {
let ctor_node_id = variant.node.data.ctor_id().unwrap_or(variant.node.id);
let ctor_def_id = self.definitions.local_def_id(ctor_node_id);
let ctor_kind = CtorKind::from_ast(&variant.node.data);
let ctor_def = Def::Ctor(CtorOf::Variant, ctor_def_id, ctor_kind);
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
self.define(parent, ident, ValueNS, (ctor_def, vis, variant.span, expansion));
}

Expand Down Expand Up @@ -654,10 +654,10 @@ impl<'a> Resolver<'a> {
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
}
Def::Fn(..) | Def::Static(..) | Def::Const(..) |
Def::Ctor(CtorOf::Variant, ..) => {
Def::Ctor(_, CtorOf::Variant, ..) => {
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));
}
Def::Ctor(CtorOf::Struct, def_id, ..) => {
Def::Ctor(def_id, CtorOf::Struct, ..) => {
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));

if let Some(struct_def_id) =
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/lib.rs
Expand Up @@ -1360,7 +1360,7 @@ impl<'a> NameBinding<'a> {
fn is_variant(&self) -> bool {
match self.kind {
NameBindingKind::Def(Def::Variant(..), _) |
NameBindingKind::Def(Def::Ctor(CtorOf::Variant, ..), _) => true,
NameBindingKind::Def(Def::Ctor(_, CtorOf::Variant, ..), _) => true,
_ => false,
}
}
Expand Down Expand Up @@ -4452,7 +4452,7 @@ impl<'a> Resolver<'a> {
// outside crate private modules => no need to check this)
if !in_module_is_extern || name_binding.vis == ty::Visibility::Public {
let did = match def {
Def::Ctor(_, did, _) => self.parent(did),
Def::Ctor(did, ..) => self.parent(did),
_ => def.opt_def_id(),
};
candidates.push(ImportSuggestion { did, path });
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Expand Up @@ -757,7 +757,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
ref_id: id_from_def_id(def_id),
})
}
HirDef::Ctor(CtorOf::Struct, def_id, _) => {
HirDef::Ctor(def_id, CtorOf::Struct, ..) => {
// This is a reference to a tuple struct where the def_id points
// to an invisible constructor function. That is not a very useful
// def, so adjust to point to the tuple struct itself.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -1596,7 +1596,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {

match def {
// Case 1. Reference to a struct constructor.
Def::Ctor(CtorOf::Struct, def_id, ..) |
Def::Ctor(def_id, CtorOf::Struct, ..) |
Def::SelfCtor(.., def_id) => {
// Everything but the final segment should have no
// parameters at all.
Expand All @@ -1608,7 +1608,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
}

// Case 2. Reference to a variant constructor.
Def::Ctor(CtorOf::Variant, def_id, ..) | Def::Variant(def_id, ..) => {
Def::Ctor(def_id, CtorOf::Variant, ..) | Def::Variant(def_id, ..) => {
let adt_def = self_ty.map(|t| t.ty_adt_def().unwrap());
let (generics_def_id, index) = if let Some(adt_def) = adt_def {
debug_assert!(adt_def.is_enum());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/mod.rs
Expand Up @@ -422,7 +422,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// them as well. It's ok to use the variant's id as a ctor id since an
// error will be reported on any use of such resolution anyway.
let ctor_def_id = variant_def.ctor_def_id.unwrap_or(variant_def.def_id);
let def = Def::Ctor(CtorOf::Variant, ctor_def_id, variant_def.ctor_kind);
let def = Def::Ctor(ctor_def_id, CtorOf::Variant, variant_def.ctor_kind);
tcx.check_stability(def.def_id(), Some(expr_id), span);
return Ok(def);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -5345,7 +5345,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(adt_def) if adt_def.has_ctor() => {
let variant = adt_def.non_enum_variant();
let ctor_def_id = variant.ctor_def_id.unwrap();
let def = Def::Ctor(CtorOf::Struct, ctor_def_id, variant.ctor_kind);
let def = Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind);
(def, ctor_def_id, tcx.type_of(ctor_def_id))
}
_ => {
Expand Down Expand Up @@ -5418,7 +5418,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let mut user_self_ty = None;
let mut is_alias_variant_ctor = false;
match def {
Def::Ctor(CtorOf::Variant, _, _) => {
Def::Ctor(_, CtorOf::Variant, _) => {
if let Some(self_ty) = self_ty {
let adt_def = self_ty.ty_adt_def().unwrap();
user_self_ty = Some(UserSelfTy {
Expand Down

0 comments on commit 23cae1d

Please sign in to comment.