From 23cae1d3f06ccb339f2f780e63b6d6d5c1c6a9da Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 24 Mar 2019 19:16:44 +0100 Subject: [PATCH] Re-order fields in `Def::Ctor`. This commit moves the `DefId` field of `Def::Ctor` to be the first field. --- src/librustc/hir/def.rs | 16 ++++++++-------- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/pat_util.rs | 2 +- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/mem_categorization.rs | 6 +++--- src/librustc/ty/mod.rs | 6 +++--- src/librustc_metadata/decoder.rs | 5 ++--- src/librustc_mir/hair/cx/expr.rs | 6 +++--- src/librustc_mir/hair/pattern/mod.rs | 4 ++-- src/librustc_resolve/build_reduced_graph.rs | 10 +++++----- src/librustc_resolve/lib.rs | 4 ++-- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_typeck/astconv.rs | 4 ++-- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/mod.rs | 4 ++-- 16 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index e30d4a1a648e1..3cc23ccdb642c 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -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), @@ -276,7 +276,7 @@ impl Def { pub fn opt_def_id(&self) -> Option { 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) | @@ -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", diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index b94ccd90abdad..d810a9310c55f 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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(_) | diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index bce559b17fa00..e7eda5aab133f 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -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), _ => () } } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index da62423000261..f12367a89bbf3 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -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); diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index f92331b35d847..6c8d9fe29d7a0 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -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); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index c907cbba4fd2f..4b169dea06c7c 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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, _) => { @@ -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) } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index f32b290a7e6bf..f0045136f41bf 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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(), @@ -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() } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index ecce27f4969d6..fb519407398fe 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -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 }); } @@ -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 }); } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 805d386b190be..2ca44ecaba220 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -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, @@ -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; @@ -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); diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 83a281ac7a791..6c532fce57f0e 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -734,7 +734,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { subpatterns: Vec>, ) -> 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) }, @@ -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 } } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index a62df699e050b..80cb14deac49a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -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)); @@ -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)); } @@ -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) = diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 5021353b7dff8..a2b052044ce74 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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, } } @@ -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 }); diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 96a0b364678c3..828ef802dd714 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -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. diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 3d289a5c48df8..3e61b175b76e0 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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. @@ -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()); diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 5c6bbe2dee5af..34a24308e491a 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -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); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1c3c0f479f699..94f76b03a643c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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)) } _ => { @@ -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 {