@@ -366,12 +366,18 @@ impl<'hir> Map<'hir> {
366366 }
367367 }
368368 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 ) ;
370370 Some ( Def :: Variant ( def_id) )
371371 }
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) ) )
375381 }
376382 Node :: AnonConst ( _) |
377383 Node :: Field ( _) |
@@ -516,8 +522,7 @@ impl<'hir> Map<'hir> {
516522 Node :: AnonConst ( _) => {
517523 BodyOwnerKind :: Const
518524 }
519- Node :: Variant ( & Spanned { node : VariantKind { data : VariantData :: Tuple ( ..) , .. } , .. } ) |
520- Node :: StructCtor ( ..) |
525+ Node :: Ctor ( ..) |
521526 Node :: Item ( & Item { node : ItemKind :: Fn ( ..) , .. } ) |
522527 Node :: TraitItem ( & TraitItem { node : TraitItemKind :: Method ( ..) , .. } ) |
523528 Node :: ImplItem ( & ImplItem { node : ImplItemKind :: Method ( ..) , .. } ) => {
@@ -948,8 +953,8 @@ impl<'hir> Map<'hir> {
948953 _ => bug ! ( "struct ID bound to non-struct {}" , self . hir_to_string( id) )
949954 }
950955 }
951- Some ( Node :: StructCtor ( data) ) => data,
952956 Some ( Node :: Variant ( variant) ) => & variant. node . data ,
957+ Some ( Node :: Ctor ( data) ) => data,
953958 _ => bug ! ( "expected struct or variant, found {}" , self . hir_to_string( id) )
954959 }
955960 }
@@ -993,7 +998,7 @@ impl<'hir> Map<'hir> {
993998 Node :: Lifetime ( lt) => lt. name . ident ( ) . name ,
994999 Node :: GenericParam ( param) => param. name . ident ( ) . name ,
9951000 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) ) ,
9971002 _ => bug ! ( "no name for {}" , self . node_to_string( id) )
9981003 }
9991004 }
@@ -1019,9 +1024,9 @@ impl<'hir> Map<'hir> {
10191024 Some ( Node :: Expr ( ref e) ) => Some ( & * e. attrs ) ,
10201025 Some ( Node :: Stmt ( ref s) ) => Some ( s. node . attrs ( ) ) ,
10211026 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) ) ,
10251030 _ => None
10261031 } ;
10271032 attrs. unwrap_or ( & [ ] )
@@ -1068,7 +1073,11 @@ impl<'hir> Map<'hir> {
10681073 Some ( Node :: Binding ( pat) ) => pat. span ,
10691074 Some ( Node :: Pat ( pat) ) => pat. span ,
10701075 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+ }
10721081 Some ( Node :: Lifetime ( lifetime) ) => lifetime. span ,
10731082 Some ( Node :: GenericParam ( param) ) => param. span ,
10741083 Some ( Node :: Visibility ( & Spanned {
@@ -1324,7 +1333,7 @@ impl<'a> print::State<'a> {
13241333 // these cases do not carry enough information in the
13251334 // hir_map to reconstruct their full structure for pretty
13261335 // printing.
1327- Node :: StructCtor ( _ ) => bug ! ( "cannot print isolated StructCtor " ) ,
1336+ Node :: Ctor ( .. ) => bug ! ( "cannot print isolated Ctor " ) ,
13281337 Node :: Local ( a) => self . print_local_decl ( & a) ,
13291338 Node :: MacroDef ( _) => bug ! ( "cannot print MacroDef" ) ,
13301339 Node :: Crate => bug ! ( "cannot print Crate" ) ,
@@ -1443,8 +1452,8 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
14431452 Some ( Node :: Local ( _) ) => {
14441453 format ! ( "local {}{}" , map. node_to_pretty_string( id) , id_str)
14451454 }
1446- Some ( Node :: StructCtor ( _ ) ) => {
1447- format ! ( "struct_ctor {}{}" , path_str( ) , id_str)
1455+ Some ( Node :: Ctor ( .. ) ) => {
1456+ format ! ( "ctor {}{}" , path_str( ) , id_str)
14481457 }
14491458 Some ( Node :: Lifetime ( _) ) => {
14501459 format ! ( "lifetime {}{}" , map. node_to_pretty_string( id) , id_str)
0 commit comments