@@ -1427,7 +1427,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14271427 & adt_def
14281428 . variants ( )
14291429 . iter ( )
1430- . map ( |variant| variant. name )
1430+ . map ( |variant| variant. name ( ) )
14311431 . collect :: < Vec < Symbol > > ( ) ,
14321432 assoc_ident. name ,
14331433 None ,
@@ -2524,6 +2524,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25242524 self . ty_infer ( None , ast_ty. span )
25252525 }
25262526 hir:: TyKind :: Err ( guar) => Ty :: new_error ( tcx, * guar) ,
2527+ & hir:: TyKind :: AnonStruct ( fields, hir_id) | & hir:: TyKind :: AnonUnion ( fields, hir_id) => {
2528+ let repr = tcx. repr_options_of_def ( hir_id. owner . to_def_id ( ) ) ;
2529+ if !repr. c ( ) {
2530+ // tcx.sess.emit_err(todo!());
2531+ }
2532+ let adt_kind = match ast_ty. kind {
2533+ hir:: TyKind :: AnonStruct ( ..) => ty:: AdtKind :: Struct ,
2534+ _ => ty:: AdtKind :: Union ,
2535+ } ;
2536+ let field_def = tcx. hir ( ) . expect_field ( tcx. hir ( ) . parent_id ( hir_id) ) ;
2537+ let did = field_def. def_id ;
2538+ let variants = std:: iter:: once ( convert_variant (
2539+ tcx,
2540+ did,
2541+ fields,
2542+ adt_kind,
2543+ ) )
2544+ . collect ( ) ;
2545+ let adt_def = tcx. mk_adt_def ( did. to_def_id ( ) , adt_kind, variants, repr) ;
2546+ Ty :: new_adt ( tcx, adt_def, tcx. mk_args ( & [ ] ) )
2547+ }
25272548 } ;
25282549
25292550 self . record_ty ( ast_ty. hir_id , result_ty, ast_ty. span ) ;
@@ -2813,3 +2834,38 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28132834 Some ( r)
28142835 }
28152836}
2837+
2838+ fn convert_variant (
2839+ tcx : TyCtxt < ' _ > ,
2840+ did : LocalDefId ,
2841+ fields : & [ hir:: FieldDef < ' _ > ] ,
2842+ adt_kind : ty:: AdtKind ,
2843+ ) -> ty:: VariantDef {
2844+ let mut seen_fields: FxHashMap < Ident , Span > = Default :: default ( ) ;
2845+ let fields = fields
2846+ . iter ( )
2847+ . map ( |f| {
2848+ let dup_span = seen_fields. get ( & f. ident . normalize_to_macros_2_0 ( ) ) . cloned ( ) ;
2849+ if let Some ( prev_span) = dup_span {
2850+ tcx. sess . emit_err ( crate :: errors:: FieldAlreadyDeclared {
2851+ field_name : f. ident ,
2852+ span : f. span ,
2853+ prev_span,
2854+ } ) ;
2855+ } else {
2856+ seen_fields. insert ( f. ident . normalize_to_macros_2_0 ( ) , f. span ) ;
2857+ }
2858+
2859+ ty:: FieldDef {
2860+ did : f. def_id . to_def_id ( ) ,
2861+ name : f. ident . name ,
2862+ vis : tcx. visibility ( f. def_id ) ,
2863+ }
2864+ } )
2865+ . collect ( ) ;
2866+ ty:: VariantDef :: new_anon (
2867+ did. to_def_id ( ) ,
2868+ fields,
2869+ adt_kind,
2870+ )
2871+ }
0 commit comments