@@ -80,6 +80,22 @@ impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
80
80
let name = field. ident . map_or_else ( || sym:: integer ( index ( self ) ) , |ident| ident. name ) ;
81
81
let def = self . create_def ( field. id , name, DefKind :: Field , field. span ) ;
82
82
self . with_parent ( def, |this| visit:: walk_field_def ( this, field) ) ;
83
+ self . visit_anon_adt ( & field. ty ) ;
84
+ }
85
+ }
86
+
87
+ fn visit_anon_adt ( & mut self , ty : & ' a Ty ) {
88
+ let def_kind = match & ty. kind {
89
+ TyKind :: AnonStruct ( ..) => DefKind :: Struct ,
90
+ TyKind :: AnonUnion ( ..) => DefKind :: Union ,
91
+ _ => return ,
92
+ } ;
93
+ match & ty. kind {
94
+ TyKind :: AnonStruct ( node_id, _) | TyKind :: AnonUnion ( node_id, _) => {
95
+ let def_id = self . create_def ( * node_id, kw:: Empty , def_kind, ty. span ) ;
96
+ self . with_parent ( def_id, |this| visit:: walk_ty ( this, ty) ) ;
97
+ }
98
+ _ => { } ,
83
99
}
84
100
}
85
101
@@ -320,19 +336,8 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
320
336
fn visit_ty ( & mut self , ty : & ' a Ty ) {
321
337
match & ty. kind {
322
338
TyKind :: MacCall ( ..) => self . visit_macro_invoc ( ty. id ) ,
323
- TyKind :: AnonStruct ( node_id, fields) | TyKind :: AnonUnion ( node_id, fields) => {
324
- let def_kind = match & ty. kind {
325
- TyKind :: AnonStruct ( ..) => DefKind :: Struct ,
326
- TyKind :: AnonUnion ( ..) => DefKind :: Union ,
327
- _ => unreachable ! ( ) ,
328
- } ;
329
- let def_id = self . create_def ( * node_id, kw:: Empty , def_kind, ty. span ) ;
330
- self . with_parent ( def_id, |this| {
331
- for f in fields {
332
- this. visit_field_def ( f) ;
333
- }
334
- } ) ;
335
- }
339
+ // Anonymous structs or unions are visited later after defined.
340
+ TyKind :: AnonStruct ( ..) | TyKind :: AnonUnion ( ..) => { }
336
341
_ => visit:: walk_ty ( self , ty) ,
337
342
}
338
343
}
0 commit comments