@@ -1288,17 +1288,44 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12881288 TyKind :: Err => {
12891289 hir:: TyKind :: Err ( self . dcx ( ) . span_delayed_bug ( t. span , "TyKind::Err lowered" ) )
12901290 }
1291- // FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1292- #[ allow( rustc:: untranslatable_diagnostic) ]
1293- #[ allow( rustc:: diagnostic_outside_of_impl) ]
1294- TyKind :: AnonStruct ( ref _fields) => {
1295- hir:: TyKind :: Err ( self . dcx ( ) . span_err ( t. span , "anonymous structs are unimplemented" ) )
1296- }
1297- // FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1298- #[ allow( rustc:: untranslatable_diagnostic) ]
1299- #[ allow( rustc:: diagnostic_outside_of_impl) ]
1300- TyKind :: AnonUnion ( ref _fields) => {
1301- hir:: TyKind :: Err ( self . dcx ( ) . span_err ( t. span , "anonymous unions are unimplemented" ) )
1291+ // Lower the anonymous structs or unions in a nested lowering context.
1292+ //
1293+ // ```
1294+ // struct Foo {
1295+ // _: union {
1296+ // // ^__________________ <-- within the nested lowering context,
1297+ // /* fields */ // | we lower all fields defined into an
1298+ // } // | owner node of struct or union item
1299+ // // ^_____________________|
1300+ // }
1301+ // ```
1302+ TyKind :: AnonStruct ( node_id, fields) | TyKind :: AnonUnion ( node_id, fields) => {
1303+ // Here its `def_id` is created in `build_reduced_graph`.
1304+ let def_id = self . local_def_id ( * node_id) ;
1305+ debug ! ( ?def_id) ;
1306+ let owner_id = hir:: OwnerId { def_id } ;
1307+ self . with_hir_id_owner ( * node_id, |this| {
1308+ let fields = this. arena . alloc_from_iter (
1309+ fields. iter ( ) . enumerate ( ) . map ( |f| this. lower_field_def ( f) ) ,
1310+ ) ;
1311+ let span = t. span ;
1312+ let variant_data = hir:: VariantData :: Struct { fields, recovered : false } ;
1313+ // FIXME: capture the generics from the outer adt.
1314+ let generics = hir:: Generics :: empty ( ) ;
1315+ let kind = match t. kind {
1316+ TyKind :: AnonStruct ( ..) => hir:: ItemKind :: Struct ( variant_data, generics) ,
1317+ TyKind :: AnonUnion ( ..) => hir:: ItemKind :: Union ( variant_data, generics) ,
1318+ _ => unreachable ! ( ) ,
1319+ } ;
1320+ hir:: OwnerNode :: Item ( this. arena . alloc ( hir:: Item {
1321+ ident : Ident :: new ( kw:: Empty , span) ,
1322+ owner_id,
1323+ kind,
1324+ span : this. lower_span ( span) ,
1325+ vis_span : this. lower_span ( span. shrink_to_lo ( ) ) ,
1326+ } ) )
1327+ } ) ;
1328+ hir:: TyKind :: AnonAdt ( hir:: ItemId { owner_id } )
13021329 }
13031330 TyKind :: Slice ( ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
13041331 TyKind :: Ptr ( mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
0 commit comments