@@ -9,6 +9,15 @@ use crate::ty;
9
9
10
10
use self :: Namespace :: * ;
11
11
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
+
12
21
#[ derive( Clone , Copy , PartialEq , Eq , RustcEncodable , RustcDecodable , Hash , Debug , HashStable ) ]
13
22
pub enum CtorKind {
14
23
/// Constructor function automatically created by a tuple struct/variant.
@@ -37,9 +46,11 @@ pub enum NonMacroAttrKind {
37
46
pub enum Def {
38
47
// Type namespace
39
48
Mod ( DefId ) ,
40
- Struct ( DefId ) , // `DefId` refers to `NodeId` of the struct itself
49
+ /// `DefId` refers to the struct itself, `Def::Ctor` refers to its constructor if it exists.
50
+ Struct ( DefId ) ,
41
51
Union ( DefId ) ,
42
52
Enum ( DefId ) ,
53
+ /// `DefId` refers to the variant itself, `Def::Ctor` refers to its constructor if it exists.
43
54
Variant ( DefId ) ,
44
55
Trait ( DefId ) ,
45
56
/// `existential type Foo: Bar;`
@@ -61,8 +72,8 @@ pub enum Def {
61
72
Const ( DefId ) ,
62
73
ConstParam ( DefId ) ,
63
74
Static ( DefId , bool /* is_mutbl */ ) ,
64
- StructCtor ( DefId , CtorKind ) , // `DefId` refers to `NodeId` of the struct's constructor
65
- VariantCtor ( DefId , CtorKind ) , // `DefId` refers to the enum variant
75
+ /// `DefId` refers to the struct or enum variant 's constructor.
76
+ Ctor ( DefId , CtorOf , CtorKind ) ,
66
77
SelfCtor ( DefId /* impl */ ) , // `DefId` refers to the impl
67
78
Method ( DefId ) ,
68
79
AssociatedConst ( DefId ) ,
@@ -265,10 +276,9 @@ impl Def {
265
276
pub fn opt_def_id ( & self ) -> Option < DefId > {
266
277
match * self {
267
278
Def :: Fn ( id) | Def :: Mod ( id) | Def :: Static ( id, _) |
268
- Def :: Variant ( id) | Def :: VariantCtor ( id, ..) | Def :: Enum ( id) |
279
+ Def :: Variant ( id) | Def :: Ctor ( id, ..) | Def :: Enum ( id) |
269
280
Def :: TyAlias ( id) | Def :: TraitAlias ( id) |
270
281
Def :: AssociatedTy ( id) | Def :: TyParam ( id) | Def :: ConstParam ( id) | Def :: Struct ( id) |
271
- Def :: StructCtor ( id, ..) |
272
282
Def :: Union ( id) | Def :: Trait ( id) | Def :: Method ( id) | Def :: Const ( id) |
273
283
Def :: AssociatedConst ( id) | Def :: Macro ( id, ..) |
274
284
Def :: Existential ( id) | Def :: AssociatedExistential ( id) | Def :: ForeignTy ( id) => {
@@ -303,20 +313,21 @@ impl Def {
303
313
Def :: Fn ( ..) => "function" ,
304
314
Def :: Mod ( ..) => "module" ,
305
315
Def :: Static ( ..) => "static" ,
306
- Def :: Variant ( ..) => "variant" ,
307
- Def :: VariantCtor ( .., CtorKind :: Fn ) => "tuple variant" ,
308
- Def :: VariantCtor ( .., CtorKind :: Const ) => "unit variant" ,
309
- Def :: VariantCtor ( .., CtorKind :: Fictive ) => "struct variant" ,
310
316
Def :: Enum ( ..) => "enum" ,
317
+ 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" ,
321
+ 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 ) =>
325
+ bug ! ( "impossible struct constructor" ) ,
311
326
Def :: Existential ( ..) => "existential type" ,
312
327
Def :: TyAlias ( ..) => "type alias" ,
313
328
Def :: TraitAlias ( ..) => "trait alias" ,
314
329
Def :: AssociatedTy ( ..) => "associated type" ,
315
330
Def :: AssociatedExistential ( ..) => "associated existential type" ,
316
- Def :: Struct ( ..) => "struct" ,
317
- Def :: StructCtor ( .., CtorKind :: Fn ) => "tuple struct" ,
318
- Def :: StructCtor ( .., CtorKind :: Const ) => "unit struct" ,
319
- Def :: StructCtor ( .., CtorKind :: Fictive ) => bug ! ( "impossible struct constructor" ) ,
320
331
Def :: SelfCtor ( ..) => "self constructor" ,
321
332
Def :: Union ( ..) => "union" ,
322
333
Def :: Trait ( ..) => "trait" ,
0 commit comments