@@ -1063,11 +1063,7 @@ fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10631063 check_simd ( tcx, span, def_id) ;
10641064 }
10651065
1066- // if struct is packed and not aligned, check fields for alignment.
1067- // Checks for combining packed and align attrs on single struct are done elsewhere.
1068- if tcx. adt_def ( def_id) . repr . packed ( ) && tcx. adt_def ( def_id) . repr . align == 0 {
1069- check_packed ( tcx, span, def_id) ;
1070- }
1066+ check_packed ( tcx, span, def_id) ;
10711067}
10721068
10731069fn check_union < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -1077,6 +1073,8 @@ fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10771073 let def = tcx. adt_def ( def_id) ;
10781074 def. destructor ( tcx) ; // force the destructor to be evaluated
10791075 check_representable ( tcx, span, def_id) ;
1076+
1077+ check_packed ( tcx, span, def_id) ;
10801078}
10811079
10821080pub fn check_item_type < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , it : & ' tcx hir:: Item ) {
@@ -1478,9 +1476,15 @@ pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId
14781476}
14791477
14801478fn check_packed < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , sp : Span , def_id : DefId ) {
1481- if check_packed_inner ( tcx, def_id, & mut Vec :: new ( ) ) {
1482- struct_span_err ! ( tcx. sess, sp, E0588 ,
1483- "packed struct cannot transitively contain a `[repr(align)]` struct" ) . emit ( ) ;
1479+ if tcx. adt_def ( def_id) . repr . packed ( ) {
1480+ if tcx. adt_def ( def_id) . repr . align > 0 {
1481+ struct_span_err ! ( tcx. sess, sp, E0587 ,
1482+ "type has conflicting packed and align representation hints" ) . emit ( ) ;
1483+ }
1484+ else if check_packed_inner ( tcx, def_id, & mut Vec :: new ( ) ) {
1485+ struct_span_err ! ( tcx. sess, sp, E0588 ,
1486+ "packed type cannot transitively contain a `[repr(align)]` type" ) . emit ( ) ;
1487+ }
14841488 }
14851489}
14861490
@@ -1493,7 +1497,7 @@ fn check_packed_inner<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
14931497 return false ;
14941498 }
14951499 match t. sty {
1496- ty:: TyAdt ( def, substs) if def. is_struct ( ) => {
1500+ ty:: TyAdt ( def, substs) if def. is_struct ( ) || def . is_union ( ) => {
14971501 if tcx. adt_def ( def. did ) . repr . align > 0 {
14981502 return true ;
14991503 }
0 commit comments