@@ -366,12 +366,18 @@ impl<'hir> Map<'hir> {
366
366
}
367
367
}
368
368
Node :: Variant ( variant) => {
369
- let def_id = self . local_def_id_from_hir_id ( variant. node . data . hir_id ( ) ) ;
369
+ let def_id = self . local_def_id_from_hir_id ( variant. node . id ) ;
370
370
Some ( Def :: Variant ( def_id) )
371
371
}
372
- Node :: StructCtor ( variant) => {
373
- let def_id = self . local_def_id_from_hir_id ( variant. hir_id ( ) ) ;
374
- Some ( Def :: StructCtor ( def_id, def:: CtorKind :: from_hir ( variant) ) )
372
+ Node :: Ctor ( variant_data) => {
373
+ let ctor_of = match self . find ( self . get_parent_node ( node_id) ) {
374
+ Some ( Node :: Item ( ..) ) => def:: CtorOf :: Struct ,
375
+ Some ( Node :: Variant ( ..) ) => def:: CtorOf :: Variant ,
376
+ _ => unreachable ! ( ) ,
377
+ } ;
378
+ variant_data. ctor_hir_id ( )
379
+ . map ( |hir_id| self . local_def_id_from_hir_id ( hir_id) )
380
+ . map ( |def_id| Def :: Ctor ( def_id, ctor_of, def:: CtorKind :: from_hir ( variant_data) ) )
375
381
}
376
382
Node :: AnonConst ( _) |
377
383
Node :: Field ( _) |
@@ -516,8 +522,7 @@ impl<'hir> Map<'hir> {
516
522
Node :: AnonConst ( _) => {
517
523
BodyOwnerKind :: Const
518
524
}
519
- Node :: Variant ( & Spanned { node : VariantKind { data : VariantData :: Tuple ( ..) , .. } , .. } ) |
520
- Node :: StructCtor ( ..) |
525
+ Node :: Ctor ( ..) |
521
526
Node :: Item ( & Item { node : ItemKind :: Fn ( ..) , .. } ) |
522
527
Node :: TraitItem ( & TraitItem { node : TraitItemKind :: Method ( ..) , .. } ) |
523
528
Node :: ImplItem ( & ImplItem { node : ImplItemKind :: Method ( ..) , .. } ) => {
@@ -948,8 +953,8 @@ impl<'hir> Map<'hir> {
948
953
_ => bug ! ( "struct ID bound to non-struct {}" , self . hir_to_string( id) )
949
954
}
950
955
}
951
- Some ( Node :: StructCtor ( data) ) => data,
952
956
Some ( Node :: Variant ( variant) ) => & variant. node . data ,
957
+ Some ( Node :: Ctor ( data) ) => data,
953
958
_ => bug ! ( "expected struct or variant, found {}" , self . hir_to_string( id) )
954
959
}
955
960
}
@@ -993,7 +998,7 @@ impl<'hir> Map<'hir> {
993
998
Node :: Lifetime ( lt) => lt. name . ident ( ) . name ,
994
999
Node :: GenericParam ( param) => param. name . ident ( ) . name ,
995
1000
Node :: Binding ( & Pat { node : PatKind :: Binding ( _, _, l, _) , .. } ) => l. name ,
996
- Node :: StructCtor ( _ ) => self . name ( self . get_parent ( id) ) ,
1001
+ Node :: Ctor ( .. ) => self . name ( self . get_parent ( id) ) ,
997
1002
_ => bug ! ( "no name for {}" , self . node_to_string( id) )
998
1003
}
999
1004
}
@@ -1019,9 +1024,9 @@ impl<'hir> Map<'hir> {
1019
1024
Some ( Node :: Expr ( ref e) ) => Some ( & * e. attrs ) ,
1020
1025
Some ( Node :: Stmt ( ref s) ) => Some ( s. node . attrs ( ) ) ,
1021
1026
Some ( Node :: GenericParam ( param) ) => Some ( & param. attrs [ ..] ) ,
1022
- // unit /tuple structs take the attributes straight from
1023
- // the struct definition.
1024
- Some ( Node :: StructCtor ( _ ) ) => return self . attrs ( self . get_parent ( id) ) ,
1027
+ // Unit /tuple structs/variants take the attributes straight from
1028
+ // the struct/variant definition.
1029
+ Some ( Node :: Ctor ( .. ) ) => return self . attrs ( self . get_parent ( id) ) ,
1025
1030
_ => None
1026
1031
} ;
1027
1032
attrs. unwrap_or ( & [ ] )
@@ -1068,7 +1073,11 @@ impl<'hir> Map<'hir> {
1068
1073
Some ( Node :: Binding ( pat) ) => pat. span ,
1069
1074
Some ( Node :: Pat ( pat) ) => pat. span ,
1070
1075
Some ( Node :: Block ( block) ) => block. span ,
1071
- Some ( Node :: StructCtor ( _) ) => self . expect_item ( self . get_parent ( id) ) . span ,
1076
+ Some ( Node :: Ctor ( ..) ) => match self . find ( self . get_parent_node ( id) ) {
1077
+ Some ( Node :: Item ( item) ) => item. span ,
1078
+ Some ( Node :: Variant ( variant) ) => variant. span ,
1079
+ _ => unreachable ! ( ) ,
1080
+ }
1072
1081
Some ( Node :: Lifetime ( lifetime) ) => lifetime. span ,
1073
1082
Some ( Node :: GenericParam ( param) ) => param. span ,
1074
1083
Some ( Node :: Visibility ( & Spanned {
@@ -1324,7 +1333,7 @@ impl<'a> print::State<'a> {
1324
1333
// these cases do not carry enough information in the
1325
1334
// hir_map to reconstruct their full structure for pretty
1326
1335
// printing.
1327
- Node :: StructCtor ( _ ) => bug ! ( "cannot print isolated StructCtor " ) ,
1336
+ Node :: Ctor ( .. ) => bug ! ( "cannot print isolated Ctor " ) ,
1328
1337
Node :: Local ( a) => self . print_local_decl ( & a) ,
1329
1338
Node :: MacroDef ( _) => bug ! ( "cannot print MacroDef" ) ,
1330
1339
Node :: Crate => bug ! ( "cannot print Crate" ) ,
@@ -1443,8 +1452,8 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
1443
1452
Some ( Node :: Local ( _) ) => {
1444
1453
format ! ( "local {}{}" , map. node_to_pretty_string( id) , id_str)
1445
1454
}
1446
- Some ( Node :: StructCtor ( _ ) ) => {
1447
- format ! ( "struct_ctor {}{}" , path_str( ) , id_str)
1455
+ Some ( Node :: Ctor ( .. ) ) => {
1456
+ format ! ( "ctor {}{}" , path_str( ) , id_str)
1448
1457
}
1449
1458
Some ( Node :: Lifetime ( _) ) => {
1450
1459
format ! ( "lifetime {}{}" , map. node_to_pretty_string( id) , id_str)
0 commit comments