@@ -810,13 +810,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
810
810
let adt_def = self . tcx . adt_def ( def_id) ;
811
811
assert ! ( adt_def. is_union( ) ) ;
812
812
assert_eq ! ( idx, FIRST_VARIANT ) ;
813
- let dest = adt_def. non_enum_variant ( ) . fields [ field] . ty ( self . tcx , args) ;
814
- if fields. len ( ) != 1 {
813
+ let dest_ty = self . tcx . normalize_erasing_regions (
814
+ self . param_env ,
815
+ adt_def. non_enum_variant ( ) . fields [ field] . ty ( self . tcx , args) ,
816
+ ) ;
817
+ if fields. len ( ) == 1 {
818
+ let src_ty = fields. raw [ 0 ] . ty ( self . body , self . tcx ) ;
819
+ if !self . mir_assign_valid_types ( src_ty, dest_ty) {
820
+ self . fail ( location, "union field has the wrong type" ) ;
821
+ }
822
+ } else {
815
823
self . fail ( location, "unions should have one initialized field" ) ;
816
824
}
817
- if !self . mir_assign_valid_types ( fields. raw [ 0 ] . ty ( self . body , self . tcx ) , dest) {
818
- self . fail ( location, "union field has the wrong type" ) ;
819
- }
820
825
}
821
826
AggregateKind :: Adt ( def_id, idx, args, _, None ) => {
822
827
let adt_def = self . tcx . adt_def ( def_id) ;
@@ -826,10 +831,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
826
831
self . fail ( location, "adt has the wrong number of initialized fields" ) ;
827
832
}
828
833
for ( src, dest) in std:: iter:: zip ( fields, & variant. fields ) {
829
- if ! self . mir_assign_valid_types (
830
- src . ty ( self . body , self . tcx ) ,
831
- dest. ty ( self . tcx , args) ,
832
- ) {
834
+ let dest_ty = self
835
+ . tcx
836
+ . normalize_erasing_regions ( self . param_env , dest. ty ( self . tcx , args) ) ;
837
+ if ! self . mir_assign_valid_types ( src . ty ( self . body , self . tcx ) , dest_ty ) {
833
838
self . fail ( location, "adt field has the wrong type" ) ;
834
839
}
835
840
}
0 commit comments