@@ -1326,18 +1326,50 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1326
1326
TyKind :: Err => {
1327
1327
hir:: TyKind :: Err ( self . tcx . sess . span_delayed_bug ( t. span , "TyKind::Err lowered" ) )
1328
1328
}
1329
- // FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1330
- #[ allow( rustc:: untranslatable_diagnostic) ]
1331
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
1332
- TyKind :: AnonStruct ( ref _fields) => hir:: TyKind :: Err (
1333
- self . tcx . sess . span_err ( t. span , "anonymous structs are unimplemented" ) ,
1334
- ) ,
1335
- // FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
1336
- #[ allow( rustc:: untranslatable_diagnostic) ]
1337
- #[ allow( rustc:: diagnostic_outside_of_impl) ]
1338
- TyKind :: AnonUnion ( ref _fields) => hir:: TyKind :: Err (
1339
- self . tcx . sess . span_err ( t. span , "anonymous unions are unimplemented" ) ,
1340
- ) ,
1329
+ // Lower the anonymous structs or unions in a nested lowering context.
1330
+ //
1331
+ // ```
1332
+ // struct Foo {
1333
+ // _: union {
1334
+ // // ^__________________ <-- within the nested lowering context,
1335
+ // /* fields */ // | we lower all fields defined into an
1336
+ // } // | owner node of struct or union item
1337
+ // // ^_____________________|
1338
+ // }
1339
+ //
1340
+ TyKind :: AnonStruct ( def_node_id, fields) | TyKind :: AnonUnion ( def_node_id, fields) => {
1341
+ let ( def_kind, item_kind) : ( DefKind , fn ( _, _) -> _ ) = match t. kind {
1342
+ TyKind :: AnonStruct ( ..) => ( DefKind :: Struct , hir:: ItemKind :: Struct ) ,
1343
+ TyKind :: AnonUnion ( ..) => ( DefKind :: Union , hir:: ItemKind :: Union ) ,
1344
+ _ => unreachable ! ( ) ,
1345
+ } ;
1346
+ let def_id = self . create_def (
1347
+ self . current_hir_id_owner . def_id ,
1348
+ * def_node_id,
1349
+ kw:: Empty ,
1350
+ def_kind,
1351
+ t. span ,
1352
+ ) ;
1353
+ debug ! ( ?def_id) ;
1354
+ let owner_id = hir:: OwnerId { def_id } ;
1355
+ self . with_hir_id_owner ( * def_node_id, |this| {
1356
+ let fields = this. arena . alloc_from_iter (
1357
+ fields. iter ( ) . enumerate ( ) . map ( |f| this. lower_field_def ( f) ) ,
1358
+ ) ;
1359
+ let span = t. span ;
1360
+ let variant_data = hir:: VariantData :: Struct ( fields, false ) ;
1361
+ // FIXME: capture the generics from the outer adt.
1362
+ let generics = hir:: Generics :: empty ( ) ;
1363
+ hir:: OwnerNode :: Item ( this. arena . alloc ( hir:: Item {
1364
+ ident : Ident :: new ( kw:: Empty , span) ,
1365
+ owner_id,
1366
+ kind : item_kind ( variant_data, generics) ,
1367
+ span : this. lower_span ( span) ,
1368
+ vis_span : this. lower_span ( span. shrink_to_lo ( ) ) ,
1369
+ } ) )
1370
+ } ) ;
1371
+ hir:: TyKind :: AnonAdt ( hir:: ItemId { owner_id } )
1372
+ }
1341
1373
TyKind :: Slice ( ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
1342
1374
TyKind :: Ptr ( mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
1343
1375
TyKind :: Ref ( region, mt) => {
0 commit comments