@@ -1288,17 +1288,49 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1288
1288
TyKind :: Err => {
1289
1289
hir:: TyKind :: Err ( self . dcx ( ) . span_delayed_bug ( t. span , "TyKind::Err lowered" ) )
1290
1290
}
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 ( def_node_id, fields) | TyKind :: AnonUnion ( def_node_id, fields) => {
1303
+ let ( def_kind, item_kind) : ( DefKind , fn ( _, _) -> _ ) = match t. kind {
1304
+ TyKind :: AnonStruct ( ..) => ( DefKind :: Struct , hir:: ItemKind :: Struct ) ,
1305
+ TyKind :: AnonUnion ( ..) => ( DefKind :: Union , hir:: ItemKind :: Union ) ,
1306
+ _ => unreachable ! ( ) ,
1307
+ } ;
1308
+ let def_id = self . create_def (
1309
+ self . current_hir_id_owner . def_id ,
1310
+ * def_node_id,
1311
+ kw:: Empty ,
1312
+ def_kind,
1313
+ t. span ,
1314
+ ) ;
1315
+ debug ! ( ?def_id) ;
1316
+ let owner_id = hir:: OwnerId { def_id } ;
1317
+ self . with_hir_id_owner ( * def_node_id, |this| {
1318
+ let fields = this. arena . alloc_from_iter (
1319
+ fields. iter ( ) . enumerate ( ) . map ( |f| this. lower_field_def ( f) ) ,
1320
+ ) ;
1321
+ let span = t. span ;
1322
+ let variant_data = hir:: VariantData :: Struct ( fields, false ) ;
1323
+ // FIXME: capture the generics from the outer adt.
1324
+ let generics = hir:: Generics :: empty ( ) ;
1325
+ hir:: OwnerNode :: Item ( this. arena . alloc ( hir:: Item {
1326
+ ident : Ident :: new ( kw:: Empty , span) ,
1327
+ owner_id,
1328
+ kind : item_kind ( variant_data, generics) ,
1329
+ span : this. lower_span ( span) ,
1330
+ vis_span : this. lower_span ( span. shrink_to_lo ( ) ) ,
1331
+ } ) )
1332
+ } ) ;
1333
+ hir:: TyKind :: AnonAdt ( hir:: ItemId { owner_id } )
1302
1334
}
1303
1335
TyKind :: Slice ( ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
1304
1336
TyKind :: Ptr ( mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
0 commit comments