@@ -1063,11 +1063,7 @@ fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1063
1063
check_simd ( tcx, span, def_id) ;
1064
1064
}
1065
1065
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) ;
1071
1067
}
1072
1068
1073
1069
fn check_union < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -1077,6 +1073,8 @@ fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1077
1073
let def = tcx. adt_def ( def_id) ;
1078
1074
def. destructor ( tcx) ; // force the destructor to be evaluated
1079
1075
check_representable ( tcx, span, def_id) ;
1076
+
1077
+ check_packed ( tcx, span, def_id) ;
1080
1078
}
1081
1079
1082
1080
pub 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
1478
1476
}
1479
1477
1480
1478
fn 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
+ }
1484
1488
}
1485
1489
}
1486
1490
@@ -1493,7 +1497,7 @@ fn check_packed_inner<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1493
1497
return false ;
1494
1498
}
1495
1499
match t. sty {
1496
- ty:: TyAdt ( def, substs) if def. is_struct ( ) => {
1500
+ ty:: TyAdt ( def, substs) if def. is_struct ( ) || def . is_union ( ) => {
1497
1501
if tcx. adt_def ( def. did ) . repr . align > 0 {
1498
1502
return true ;
1499
1503
}
0 commit comments