@@ -13,6 +13,16 @@ use util::nodemap::NodeMap;
13
13
use syntax:: ast;
14
14
use hir;
15
15
16
+ #[ derive( Clone , Copy , PartialEq , Eq , RustcEncodable , RustcDecodable , Hash , Debug ) ]
17
+ pub enum CtorKind {
18
+ // Constructor function automatically created by a tuple struct/variant.
19
+ Fn ,
20
+ // Constructor constant automatically created by a unit struct/variant.
21
+ Const ,
22
+ // Unusable name in value namespace created by a struct variant.
23
+ Fictive ,
24
+ }
25
+
16
26
#[ derive( Clone , Copy , PartialEq , Eq , RustcEncodable , RustcDecodable , Hash , Debug ) ]
17
27
pub enum Def {
18
28
Fn ( DefId ) ,
@@ -23,21 +33,18 @@ pub enum Def {
23
33
AssociatedConst ( DefId ) ,
24
34
Local ( DefId ) ,
25
35
Variant ( DefId ) ,
36
+ VariantCtor ( DefId , CtorKind ) ,
26
37
Enum ( DefId ) ,
27
38
TyAlias ( DefId ) ,
28
39
AssociatedTy ( DefId ) ,
29
40
Trait ( DefId ) ,
30
41
PrimTy ( hir:: PrimTy ) ,
31
42
TyParam ( DefId ) ,
32
43
Upvar ( DefId , // def id of closed over local
33
- usize , // index in the freevars list of the closure
34
- ast:: NodeId ) , // expr node that creates the closure
35
-
36
- // If Def::Struct lives in type namespace it denotes a struct item and its DefId refers
37
- // to NodeId of the struct itself.
38
- // If Def::Struct lives in value namespace (e.g. tuple struct, unit struct expressions)
39
- // it denotes a constructor and its DefId refers to NodeId of the struct's constructor.
40
- Struct ( DefId ) ,
44
+ usize , // index in the freevars list of the closure
45
+ ast:: NodeId ) , // expr node that creates the closure
46
+ Struct ( DefId ) , // DefId refers to NodeId of the struct itself
47
+ StructCtor ( DefId , CtorKind ) , // DefId refers to NodeId of the struct's constructor
41
48
Union ( DefId ) ,
42
49
Label ( ast:: NodeId ) ,
43
50
Method ( DefId ) ,
@@ -97,14 +104,24 @@ pub struct Export {
97
104
pub def_id : DefId , // The definition of the target.
98
105
}
99
106
107
+ impl CtorKind {
108
+ pub fn from_vdata ( vdata : & ast:: VariantData ) -> CtorKind {
109
+ match * vdata {
110
+ ast:: VariantData :: Tuple ( ..) => CtorKind :: Fn ,
111
+ ast:: VariantData :: Unit ( ..) => CtorKind :: Const ,
112
+ ast:: VariantData :: Struct ( ..) => CtorKind :: Fictive ,
113
+ }
114
+ }
115
+ }
116
+
100
117
impl Def {
101
118
pub fn def_id ( & self ) -> DefId {
102
119
match * self {
103
120
Def :: Fn ( id) | Def :: Mod ( id) | Def :: Static ( id, _) |
104
- Def :: Variant ( id) | Def :: Enum ( id) | Def :: TyAlias ( id) | Def :: AssociatedTy ( id) |
105
- Def :: TyParam ( id) | Def :: Struct ( id) | Def :: Union ( id) | Def :: Trait ( id) |
106
- Def :: Method ( id) | Def :: Const ( id) | Def :: AssociatedConst ( id) |
107
- Def :: Local ( id) | Def :: Upvar ( id, ..) => {
121
+ Def :: Variant ( id) | Def :: VariantCtor ( id, .. ) | Def :: Enum ( id) | Def :: TyAlias ( id) |
122
+ Def :: AssociatedTy ( id) | Def :: TyParam ( id) | Def :: Struct ( id) | Def :: StructCtor ( id, .. ) |
123
+ Def :: Union ( id) | Def :: Trait ( id) | Def :: Method ( id ) | Def :: Const ( id) |
124
+ Def :: AssociatedConst ( id ) | Def :: Local ( id) | Def :: Upvar ( id, ..) => {
108
125
id
109
126
}
110
127
@@ -123,10 +140,12 @@ impl Def {
123
140
Def :: Mod ( ..) => "module" ,
124
141
Def :: Static ( ..) => "static" ,
125
142
Def :: Variant ( ..) => "variant" ,
143
+ Def :: VariantCtor ( ..) => "variant" ,
126
144
Def :: Enum ( ..) => "enum" ,
127
145
Def :: TyAlias ( ..) => "type" ,
128
146
Def :: AssociatedTy ( ..) => "associated type" ,
129
147
Def :: Struct ( ..) => "struct" ,
148
+ Def :: StructCtor ( ..) => "struct" ,
130
149
Def :: Union ( ..) => "union" ,
131
150
Def :: Trait ( ..) => "trait" ,
132
151
Def :: Method ( ..) => "method" ,
0 commit comments