Skip to content

Commit 23cae1d

Browse files
committed
Re-order fields in Def::Ctor.
This commit moves the `DefId` field of `Def::Ctor` to be the first field.
1 parent 88f8f07 commit 23cae1d

File tree

16 files changed

+38
-39
lines changed

16 files changed

+38
-39
lines changed

src/librustc/hir/def.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum Def {
7373
ConstParam(DefId),
7474
Static(DefId, bool /* is_mutbl */),
7575
/// `DefId` refers to the struct or enum variant's constructor.
76-
Ctor(CtorOf, DefId, CtorKind),
76+
Ctor(DefId, CtorOf, CtorKind),
7777
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
7878
Method(DefId),
7979
AssociatedConst(DefId),
@@ -276,7 +276,7 @@ impl Def {
276276
pub fn opt_def_id(&self) -> Option<DefId> {
277277
match *self {
278278
Def::Fn(id) | Def::Mod(id) | Def::Static(id, _) |
279-
Def::Variant(id) | Def::Ctor(_, id, ..) | Def::Enum(id) |
279+
Def::Variant(id) | Def::Ctor(id, ..) | Def::Enum(id) |
280280
Def::TyAlias(id) | Def::TraitAlias(id) |
281281
Def::AssociatedTy(id) | Def::TyParam(id) | Def::ConstParam(id) | Def::Struct(id) |
282282
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
@@ -315,13 +315,13 @@ impl Def {
315315
Def::Static(..) => "static",
316316
Def::Enum(..) => "enum",
317317
Def::Variant(..) => "variant",
318-
Def::Ctor(CtorOf::Variant, _, CtorKind::Fn) => "tuple variant",
319-
Def::Ctor(CtorOf::Variant, _, CtorKind::Const) => "unit variant",
320-
Def::Ctor(CtorOf::Variant, _, CtorKind::Fictive) => "struct variant",
318+
Def::Ctor(_, CtorOf::Variant, CtorKind::Fn) => "tuple variant",
319+
Def::Ctor(_, CtorOf::Variant, CtorKind::Const) => "unit variant",
320+
Def::Ctor(_, CtorOf::Variant, CtorKind::Fictive) => "struct variant",
321321
Def::Struct(..) => "struct",
322-
Def::Ctor(CtorOf::Struct, _, CtorKind::Fn) => "tuple struct",
323-
Def::Ctor(CtorOf::Struct, _, CtorKind::Const) => "unit struct",
324-
Def::Ctor(CtorOf::Struct, _, CtorKind::Fictive) =>
322+
Def::Ctor(_, CtorOf::Struct, CtorKind::Fn) => "tuple struct",
323+
Def::Ctor(_, CtorOf::Struct, CtorKind::Const) => "unit struct",
324+
Def::Ctor(_, CtorOf::Struct, CtorKind::Fictive) =>
325325
bug!("impossible struct constructor"),
326326
Def::Existential(..) => "existential type",
327327
Def::TyAlias(..) => "type alias",

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'hir> Map<'hir> {
377377
};
378378
variant_data.ctor_hir_id()
379379
.map(|hir_id| self.local_def_id_from_hir_id(hir_id))
380-
.map(|def_id| Def::Ctor(ctor_of, def_id, def::CtorKind::from_hir(variant_data)))
380+
.map(|def_id| Def::Ctor(def_id, ctor_of, def::CtorKind::from_hir(variant_data)))
381381
}
382382
Node::AnonConst(_) |
383383
Node::Field(_) |

src/librustc/hir/pat_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl hir::Pat {
126126
PatKind::Struct(hir::QPath::Resolved(_, ref path), ..) => {
127127
match path.def {
128128
Def::Variant(id) => variants.push(id),
129-
Def::Ctor(CtorOf::Variant, id, _) => variants.push(id),
129+
Def::Ctor(id, CtorOf::Variant, ..) => variants.push(id),
130130
_ => ()
131131
}
132132
}

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7676
_ if self.in_pat => (),
7777
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
7878
Def::Local(..) | Def::Upvar(..) => {}
79-
Def::Ctor(CtorOf::Variant, ctor_def_id, ..) => {
79+
Def::Ctor(ctor_def_id, CtorOf::Variant, ..) => {
8080
let variant_id = self.tcx.parent(ctor_def_id).unwrap();
8181
let enum_id = self.tcx.parent(variant_id).unwrap();
8282
self.check_def_id(enum_id);

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
902902
};
903903
let def = mc.tables.qpath_def(qpath, pat.hir_id);
904904
match def {
905-
Def::Ctor(CtorOf::Variant, variant_ctor_did, ..) => {
905+
Def::Ctor(variant_ctor_did, CtorOf::Variant, ..) => {
906906
let variant_did = mc.tcx.parent(variant_ctor_did).unwrap();
907907
let downcast_cmt = mc.cat_downcast_if_needed(pat, cmt_pat, variant_did);
908908

src/librustc/middle/mem_categorization.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1274,14 +1274,14 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
12741274
debug!("access to unresolvable pattern {:?}", pat);
12751275
return Err(())
12761276
}
1277-
Def::Ctor(CtorOf::Variant, variant_ctor_did, CtorKind::Fn) => {
1277+
Def::Ctor(variant_ctor_did, CtorOf::Variant, CtorKind::Fn) => {
12781278
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
12791279
let enum_did = self.tcx.parent(variant_did).unwrap();
12801280
(self.cat_downcast_if_needed(pat, cmt, variant_did),
12811281
self.tcx.adt_def(enum_did)
12821282
.variant_with_ctor_id(variant_ctor_did).fields.len())
12831283
}
1284-
Def::Ctor(CtorOf::Struct, _, CtorKind::Fn) | Def::SelfCtor(..) => {
1284+
Def::Ctor(_, CtorOf::Struct, CtorKind::Fn) | Def::SelfCtor(..) => {
12851285
let ty = self.pat_ty_unadjusted(&pat)?;
12861286
match ty.sty {
12871287
ty::Adt(adt_def, _) => {
@@ -1316,7 +1316,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13161316
debug!("access to unresolvable pattern {:?}", pat);
13171317
return Err(())
13181318
}
1319-
Def::Ctor(CtorOf::Variant, variant_ctor_did, _) => {
1319+
Def::Ctor(variant_ctor_did, CtorOf::Variant, _) => {
13201320
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
13211321
self.cat_downcast_if_needed(pat, cmt, variant_did)
13221322
}

src/librustc/ty/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
23222322
pub fn variant_of_def(&self, def: Def) -> &VariantDef {
23232323
match def {
23242324
Def::Variant(vid) => self.variant_with_id(vid),
2325-
Def::Ctor(_, cid, ..) => self.variant_with_ctor_id(cid),
2325+
Def::Ctor(cid, ..) => self.variant_with_ctor_id(cid),
23262326
Def::Struct(..) | Def::Union(..) |
23272327
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) |
23282328
Def::SelfCtor(..) => self.non_enum_variant(),
@@ -2941,12 +2941,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
29412941
Def::Struct(did) | Def::Union(did) => {
29422942
self.adt_def(did).non_enum_variant()
29432943
}
2944-
Def::Ctor(CtorOf::Variant, variant_ctor_did, ..) => {
2944+
Def::Ctor(variant_ctor_did, CtorOf::Variant, ..) => {
29452945
let variant_did = self.parent(variant_ctor_did).unwrap();
29462946
let enum_did = self.parent(variant_did).unwrap();
29472947
self.adt_def(enum_did).variant_with_ctor_id(variant_ctor_did)
29482948
}
2949-
Def::Ctor(CtorOf::Struct, ctor_did, ..) => {
2949+
Def::Ctor(ctor_did, CtorOf::Struct, ..) => {
29502950
let struct_did = self.parent(ctor_did).expect("struct ctor has no parent");
29512951
self.adt_def(struct_did).non_enum_variant()
29522952
}

src/librustc_metadata/decoder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ impl<'a, 'tcx> CrateMetadata {
816816
Def::Struct(..) => {
817817
if let Some(ctor_def_id) = self.get_ctor_def_id(child_index) {
818818
let ctor_kind = self.get_ctor_kind(child_index);
819-
let ctor_def = Def::Ctor(
820-
hir::def::CtorOf::Struct, ctor_def_id, ctor_kind);
819+
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Struct, ctor_kind);
821820
let vis = self.get_visibility(ctor_def_id.index);
822821
callback(def::Export { def: ctor_def, vis, ident, span });
823822
}
@@ -829,7 +828,7 @@ impl<'a, 'tcx> CrateMetadata {
829828
// error will be reported on any use of such resolution anyway.
830829
let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
831830
let ctor_kind = self.get_ctor_kind(child_index);
832-
let ctor_def = Def::Ctor(CtorOf::Variant, ctor_def_id, ctor_kind);
831+
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
833832
let vis = self.get_visibility(ctor_def_id.index);
834833
callback(def::Export { def: ctor_def, ident, vis, span });
835834
}

src/librustc_mir/hair/cx/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
261261
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
262262
expr_ty.ty_adt_def().and_then(|adt_def| {
263263
match path.def {
264-
Def::Ctor(_, ctor_id, CtorKind::Fn) =>
264+
Def::Ctor(ctor_id, _, CtorKind::Fn) =>
265265
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id))),
266266
Def::SelfCtor(..) => Some((adt_def, VariantIdx::new(0))),
267267
_ => None,
@@ -675,7 +675,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
675675
.ty_adt_def()
676676
.and_then(|adt_def| {
677677
match def {
678-
Def::Ctor(CtorOf::Variant, variant_ctor_id, CtorKind::Const) => {
678+
Def::Ctor(variant_ctor_id, CtorOf::Variant, CtorKind::Const) => {
679679
let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
680680
let (d, o) = adt_def.discriminant_def_for_variant(idx);
681681
use rustc::ty::util::IntTypeExt;
@@ -951,7 +951,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
951951
}
952952
},
953953

954-
Def::Ctor(_, def_id, CtorKind::Const) => {
954+
Def::Ctor(def_id, _, CtorKind::Const) => {
955955
let user_provided_types = cx.tables.user_provided_types();
956956
let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
957957
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);

src/librustc_mir/hair/pattern/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
734734
subpatterns: Vec<FieldPattern<'tcx>>,
735735
) -> PatternKind<'tcx> {
736736
let def = match def {
737-
Def::Ctor(CtorOf::Variant, variant_ctor_id, ..) => {
737+
Def::Ctor(variant_ctor_id, CtorOf::Variant, ..) => {
738738
let variant_id = self.tcx.parent(variant_ctor_id).unwrap();
739739
Def::Variant(variant_id)
740740
},
@@ -765,7 +765,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
765765
}
766766
}
767767

768-
Def::Struct(..) | Def::Ctor(CtorOf::Struct, ..) | Def::Union(..) |
768+
Def::Struct(..) | Def::Ctor(_, CtorOf::Struct, ..) | Def::Union(..) |
769769
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) => {
770770
PatternKind::Leaf { subpatterns }
771771
}

src/librustc_resolve/build_reduced_graph.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ impl<'a> Resolver<'a> {
533533
// If this is a tuple or unit struct, define a name
534534
// in the value namespace as well.
535535
if let Some(ctor_node_id) = struct_def.ctor_id() {
536-
let ctor_def = Def::Ctor(CtorOf::Struct,
537-
self.definitions.local_def_id(ctor_node_id),
536+
let ctor_def = Def::Ctor(self.definitions.local_def_id(ctor_node_id),
537+
CtorOf::Struct,
538538
CtorKind::from_ast(struct_def));
539539
self.define(parent, ident, ValueNS, (ctor_def, ctor_vis, sp, expansion));
540540
self.struct_constructors.insert(def.def_id(), (ctor_def, ctor_vis));
@@ -596,7 +596,7 @@ impl<'a> Resolver<'a> {
596596
let ctor_node_id = variant.node.data.ctor_id().unwrap_or(variant.node.id);
597597
let ctor_def_id = self.definitions.local_def_id(ctor_node_id);
598598
let ctor_kind = CtorKind::from_ast(&variant.node.data);
599-
let ctor_def = Def::Ctor(CtorOf::Variant, ctor_def_id, ctor_kind);
599+
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
600600
self.define(parent, ident, ValueNS, (ctor_def, vis, variant.span, expansion));
601601
}
602602

@@ -654,10 +654,10 @@ impl<'a> Resolver<'a> {
654654
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
655655
}
656656
Def::Fn(..) | Def::Static(..) | Def::Const(..) |
657-
Def::Ctor(CtorOf::Variant, ..) => {
657+
Def::Ctor(_, CtorOf::Variant, ..) => {
658658
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));
659659
}
660-
Def::Ctor(CtorOf::Struct, def_id, ..) => {
660+
Def::Ctor(def_id, CtorOf::Struct, ..) => {
661661
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));
662662

663663
if let Some(struct_def_id) =

src/librustc_resolve/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ impl<'a> NameBinding<'a> {
13601360
fn is_variant(&self) -> bool {
13611361
match self.kind {
13621362
NameBindingKind::Def(Def::Variant(..), _) |
1363-
NameBindingKind::Def(Def::Ctor(CtorOf::Variant, ..), _) => true,
1363+
NameBindingKind::Def(Def::Ctor(_, CtorOf::Variant, ..), _) => true,
13641364
_ => false,
13651365
}
13661366
}
@@ -4452,7 +4452,7 @@ impl<'a> Resolver<'a> {
44524452
// outside crate private modules => no need to check this)
44534453
if !in_module_is_extern || name_binding.vis == ty::Visibility::Public {
44544454
let did = match def {
4455-
Def::Ctor(_, did, _) => self.parent(did),
4455+
Def::Ctor(did, ..) => self.parent(did),
44564456
_ => def.opt_def_id(),
44574457
};
44584458
candidates.push(ImportSuggestion { did, path });

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
757757
ref_id: id_from_def_id(def_id),
758758
})
759759
}
760-
HirDef::Ctor(CtorOf::Struct, def_id, _) => {
760+
HirDef::Ctor(def_id, CtorOf::Struct, ..) => {
761761
// This is a reference to a tuple struct where the def_id points
762762
// to an invisible constructor function. That is not a very useful
763763
// def, so adjust to point to the tuple struct itself.

src/librustc_typeck/astconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
15961596

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

16101610
// Case 2. Reference to a variant constructor.
1611-
Def::Ctor(CtorOf::Variant, def_id, ..) | Def::Variant(def_id, ..) => {
1611+
Def::Ctor(def_id, CtorOf::Variant, ..) | Def::Variant(def_id, ..) => {
16121612
let adt_def = self_ty.map(|t| t.ty_adt_def().unwrap());
16131613
let (generics_def_id, index) = if let Some(adt_def) = adt_def {
16141614
debug_assert!(adt_def.is_enum());

src/librustc_typeck/check/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
422422
// them as well. It's ok to use the variant's id as a ctor id since an
423423
// error will be reported on any use of such resolution anyway.
424424
let ctor_def_id = variant_def.ctor_def_id.unwrap_or(variant_def.def_id);
425-
let def = Def::Ctor(CtorOf::Variant, ctor_def_id, variant_def.ctor_kind);
425+
let def = Def::Ctor(ctor_def_id, CtorOf::Variant, variant_def.ctor_kind);
426426
tcx.check_stability(def.def_id(), Some(expr_id), span);
427427
return Ok(def);
428428
}

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5345,7 +5345,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53455345
Some(adt_def) if adt_def.has_ctor() => {
53465346
let variant = adt_def.non_enum_variant();
53475347
let ctor_def_id = variant.ctor_def_id.unwrap();
5348-
let def = Def::Ctor(CtorOf::Struct, ctor_def_id, variant.ctor_kind);
5348+
let def = Def::Ctor(ctor_def_id, CtorOf::Struct, variant.ctor_kind);
53495349
(def, ctor_def_id, tcx.type_of(ctor_def_id))
53505350
}
53515351
_ => {
@@ -5418,7 +5418,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
54185418
let mut user_self_ty = None;
54195419
let mut is_alias_variant_ctor = false;
54205420
match def {
5421-
Def::Ctor(CtorOf::Variant, _, _) => {
5421+
Def::Ctor(_, CtorOf::Variant, _) => {
54225422
if let Some(self_ty) = self_ty {
54235423
let adt_def = self_ty.ty_adt_def().unwrap();
54245424
user_self_ty = Some(UserSelfTy {

0 commit comments

Comments
 (0)