Skip to content

Commit 88f8f07

Browse files
committed
Move CtorOf into hir::def.
This commit moves the definition of `CtorOf` from `rustc::hir` to `rustc::hir::def` and adds imports wherever it is used.
1 parent db4770f commit 88f8f07

File tree

17 files changed

+55
-56
lines changed

17 files changed

+55
-56
lines changed

src/librustc/hir/def.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use crate::ty;
99

1010
use self::Namespace::*;
1111

12+
/// Encodes if a `Def::Ctor` is the constructor of an enum variant or a struct.
13+
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
14+
pub enum CtorOf {
15+
/// This `Def::Ctor` is a synthesized constructor of a tuple or unit struct.
16+
Struct,
17+
/// This `Def::Ctor` is a synthesized constructor of a tuple or unit variant.
18+
Variant,
19+
}
20+
1221
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
1322
pub enum CtorKind {
1423
/// Constructor function automatically created by a tuple struct/variant.
@@ -64,7 +73,7 @@ pub enum Def {
6473
ConstParam(DefId),
6574
Static(DefId, bool /* is_mutbl */),
6675
/// `DefId` refers to the struct or enum variant's constructor.
67-
Ctor(hir::CtorOf, DefId, CtorKind),
76+
Ctor(CtorOf, DefId, CtorKind),
6877
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
6978
Method(DefId),
7079
AssociatedConst(DefId),
@@ -306,13 +315,13 @@ impl Def {
306315
Def::Static(..) => "static",
307316
Def::Enum(..) => "enum",
308317
Def::Variant(..) => "variant",
309-
Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Fn) => "tuple variant",
310-
Def::Ctor(hir::CtorOf::Variant, _, CtorKind::Const) => "unit variant",
311-
Def::Ctor(hir::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",
312321
Def::Struct(..) => "struct",
313-
Def::Ctor(hir::CtorOf::Struct, _, CtorKind::Fn) => "tuple struct",
314-
Def::Ctor(hir::CtorOf::Struct, _, CtorKind::Const) => "unit struct",
315-
Def::Ctor(hir::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) =>
316325
bug!("impossible struct constructor"),
317326
Def::Existential(..) => "existential type",
318327
Def::TyAlias(..) => "type alias",

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ impl<'hir> Map<'hir> {
371371
}
372372
Node::Ctor(variant_data) => {
373373
let ctor_of = match self.find(self.get_parent_node(node_id)) {
374-
Some(Node::Item(..)) => CtorOf::Struct,
375-
Some(Node::Variant(..)) => CtorOf::Variant,
374+
Some(Node::Item(..)) => def::CtorOf::Struct,
375+
Some(Node::Variant(..)) => def::CtorOf::Variant,
376376
_ => unreachable!(),
377377
};
378378
variant_data.ctor_hir_id()

src/librustc/hir/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,15 +2559,6 @@ impl CodegenFnAttrs {
25592559
}
25602560
}
25612561

2562-
/// Encodes if a `Node::Ctor` is the constructor of an enum variant or a struct.
2563-
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
2564-
pub enum CtorOf {
2565-
/// This `Node::Ctor` is a synthesized constructor of a tuple or unit struct.
2566-
Struct,
2567-
/// This `Node::Ctor` is a synthesized constructor of a tuple or unit variant.
2568-
Variant,
2569-
}
2570-
25712562
#[derive(Copy, Clone, Debug)]
25722563
pub enum Node<'hir> {
25732564
Item(&'hir Item),

src/librustc/hir/pat_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::hir::def::Def;
1+
use crate::hir::def::{CtorOf, Def};
22
use crate::hir::def_id::DefId;
33
use crate::hir::{self, HirId, PatKind};
44
use syntax::ast;
@@ -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(hir::CtorOf::Variant, id, _) => variants.push(id),
129+
Def::Ctor(CtorOf::Variant, id, _) => variants.push(id),
130130
_ => ()
131131
}
132132
}

src/librustc/middle/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::hir::{self, PatKind, TyKind};
77
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
88
use crate::hir::itemlikevisit::ItemLikeVisitor;
99

10-
use crate::hir::def::Def;
10+
use crate::hir::def::{CtorOf, Def};
1111
use crate::hir::CodegenFnAttrFlags;
1212
use crate::hir::def_id::{DefId, LOCAL_CRATE};
1313
use crate::lint;
@@ -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(hir::CtorOf::Variant, ctor_def_id, ..) => {
79+
Def::Ctor(CtorOf::Variant, ctor_def_id, ..) => {
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use self::MatchMode::*;
99
use self::TrackMatchMode::*;
1010
use self::OverloadedCallType::*;
1111

12-
use crate::hir::def::Def;
12+
use crate::hir::def::{CtorOf, Def};
1313
use crate::hir::def_id::DefId;
1414
use crate::infer::InferCtxt;
1515
use crate::middle::mem_categorization as mc;
@@ -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(hir::CtorOf::Variant, variant_ctor_did, ..) => {
905+
Def::Ctor(CtorOf::Variant, variant_ctor_did, ..) => {
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use crate::middle::region;
6262
use crate::hir::def_id::{DefId, LocalDefId};
6363
use crate::hir::Node;
6464
use crate::infer::InferCtxt;
65-
use crate::hir::def::{Def, CtorKind};
65+
use crate::hir::def::{CtorOf, Def, CtorKind};
6666
use crate::ty::adjustment;
6767
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
6868
use crate::ty::fold::TypeFoldable;
@@ -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(hir::CtorOf::Variant, variant_ctor_did, CtorKind::Fn) => {
1277+
Def::Ctor(CtorOf::Variant, variant_ctor_did, 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(hir::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(hir::CtorOf::Variant, variant_ctor_did, _) => {
1319+
Def::Ctor(CtorOf::Variant, variant_ctor_did, _) => {
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use self::fold::TypeFoldable;
66

77
use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
88
use crate::hir::{HirId, Node};
9-
use crate::hir::def::{Def, CtorKind, ExportMap};
9+
use crate::hir::def::{Def, CtorOf, CtorKind, ExportMap};
1010
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1111
use rustc_data_structures::svh::Svh;
1212
use rustc_macros::HashStable;
@@ -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(hir::CtorOf::Variant, variant_ctor_did, ..) => {
2944+
Def::Ctor(CtorOf::Variant, variant_ctor_did, ..) => {
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(hir::CtorOf::Struct, ctor_did, ..) => {
2949+
Def::Ctor(CtorOf::Struct, ctor_did, ..) => {
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash, Definitions};
88
use rustc::hir;
99
use rustc::middle::cstore::LinkagePreference;
1010
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
11-
use rustc::hir::def::{self, Def, CtorKind};
11+
use rustc::hir::def::{self, Def, CtorOf, CtorKind};
1212
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, DefIndexAddressSpace,
1313
CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId};
1414
use rustc::hir::map::definitions::DefPathTable;
@@ -817,7 +817,7 @@ impl<'a, 'tcx> CrateMetadata {
817817
if let Some(ctor_def_id) = self.get_ctor_def_id(child_index) {
818818
let ctor_kind = self.get_ctor_kind(child_index);
819819
let ctor_def = Def::Ctor(
820-
hir::CtorOf::Struct, ctor_def_id, ctor_kind);
820+
hir::def::CtorOf::Struct, ctor_def_id, ctor_kind);
821821
let vis = self.get_visibility(ctor_def_id.index);
822822
callback(def::Export { def: ctor_def, vis, ident, span });
823823
}
@@ -829,7 +829,7 @@ impl<'a, 'tcx> CrateMetadata {
829829
// error will be reported on any use of such resolution anyway.
830830
let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
831831
let ctor_kind = self.get_ctor_kind(child_index);
832-
let ctor_def = Def::Ctor(hir::CtorOf::Variant, ctor_def_id, ctor_kind);
832+
let ctor_def = Def::Ctor(CtorOf::Variant, ctor_def_id, ctor_kind);
833833
let vis = self.get_visibility(ctor_def_id.index);
834834
callback(def::Export { def: ctor_def, ident, vis, span });
835835
}

src/librustc_mir/hair/cx/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::hair::cx::block;
44
use crate::hair::cx::to_ref::ToRef;
55
use crate::hair::util::UserAnnotatedTyHelpers;
66
use rustc_data_structures::indexed_vec::Idx;
7-
use rustc::hir::def::{Def, CtorKind};
7+
use rustc::hir::def::{CtorOf, Def, CtorKind};
88
use rustc::mir::interpret::{GlobalId, ErrorHandled, ConstValue};
99
use rustc::ty::{self, AdtKind, Ty};
1010
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability};
@@ -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(hir::CtorOf::Variant, variant_ctor_id, CtorKind::Const) => {
678+
Def::Ctor(CtorOf::Variant, variant_ctor_id, 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;

0 commit comments

Comments
 (0)