@@ -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
@@ -326,19 +342,8 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
326
342
fn visit_ty ( & mut self , ty : & ' a Ty ) {
327
343
match & ty. kind {
328
344
TyKind :: MacCall ( ..) => self . visit_macro_invoc ( ty. id ) ,
329
- TyKind :: AnonStruct ( node_id, fields) | TyKind :: AnonUnion ( node_id, fields) => {
330
- let def_kind = match & ty. kind {
331
- TyKind :: AnonStruct ( ..) => DefKind :: Struct ,
332
- TyKind :: AnonUnion ( ..) => DefKind :: Union ,
333
- _ => unreachable ! ( ) ,
334
- } ;
335
- let def_id = self . create_def ( * node_id, kw:: Empty , def_kind, ty. span ) ;
336
- self . with_parent ( def_id, |this| {
337
- for f in fields {
338
- this. visit_field_def ( f) ;
339
- }
340
- } ) ;
341
- }
345
+ // Anonymous structs or unions are visited later after defined.
346
+ TyKind :: AnonStruct ( ..) | TyKind :: AnonUnion ( ..) => { }
342
347
_ => visit:: walk_ty ( self , ty) ,
343
348
}
344
349
}
0 commit comments