@@ -1016,7 +1016,11 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1016
1016
// takes priority over transparent_with_all_zst_fields
1017
1017
if let FfiUnsafe ( explanations) = ffires_accumulator {
1018
1018
// we assume the repr() of this ADT is either non-packed C or transparent.
1019
- debug_assert ! ( def. repr( ) . c( ) || def. repr( ) . transparent( ) || def. repr( ) . int. is_some( ) ) ;
1019
+ debug_assert ! (
1020
+ ( def. repr( ) . c( ) && !def. repr( ) . packed( ) )
1021
+ || def. repr( ) . transparent( )
1022
+ || def. repr( ) . int. is_some( )
1023
+ ) ;
1020
1024
1021
1025
if def. repr ( ) . transparent ( ) || matches ! ( def. adt_kind( ) , AdtKind :: Enum ) {
1022
1026
let field_ffires = FfiUnsafe ( explanations) . wrap_all (
@@ -1086,7 +1090,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1086
1090
) -> FfiResult < ' tcx > {
1087
1091
debug_assert ! ( matches!( def. adt_kind( ) , AdtKind :: Struct | AdtKind :: Union ) ) ;
1088
1092
1089
- if !def. repr ( ) . c ( ) && !def. repr ( ) . transparent ( ) {
1093
+ if !( ( def. repr ( ) . c ( ) && !def. repr ( ) . packed ( ) ) || def. repr ( ) . transparent ( ) ) {
1094
+ // FIXME(ctypes) packed reprs prevent C compatibility, right?
1090
1095
return FfiResult :: new_with_reason (
1091
1096
ty,
1092
1097
if def. is_struct ( ) {
@@ -1162,7 +1167,10 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1162
1167
}
1163
1168
// Check for a repr() attribute to specify the size of the
1164
1169
// discriminant.
1165
- if !def. repr ( ) . c ( ) && !def. repr ( ) . transparent ( ) && def. repr ( ) . int . is_none ( ) {
1170
+ if !( def. repr ( ) . c ( ) && !def. repr ( ) . packed ( ) )
1171
+ && !def. repr ( ) . transparent ( )
1172
+ && def. repr ( ) . int . is_none ( )
1173
+ {
1166
1174
// Special-case types like `Option<extern fn()>` and `Result<extern fn(), ()>`
1167
1175
if let Some ( inner_ty) = repr_nullable_ptr ( self . cx . tcx , self . cx . typing_env ( ) , ty) {
1168
1176
return self . visit_type ( state, Some ( ty) , inner_ty) ;
@@ -1558,22 +1566,19 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1558
1566
item : & ' tcx hir:: Item < ' tcx > ,
1559
1567
adt_def : AdtDef < ' tcx > ,
1560
1568
) {
1561
- let tcx = cx. tcx ;
1562
1569
// repr(C) structs also with packed or aligned representation
1563
1570
// should be ignored.
1564
- if adt_def. repr ( ) . c ( )
1565
- && !adt_def. repr ( ) . packed ( )
1566
- && adt_def. repr ( ) . align . is_none ( )
1567
- && tcx. sess . target . os == "aix"
1568
- && !adt_def. all_fields ( ) . next ( ) . is_none ( )
1569
- {
1571
+ debug_assert ! (
1572
+ adt_def. repr( ) . c( ) && !adt_def. repr( ) . packed( ) && adt_def. repr( ) . align. is_none( )
1573
+ ) ;
1574
+ if cx. tcx . sess . target . os == "aix" && !adt_def. all_fields ( ) . next ( ) . is_none ( ) {
1570
1575
let struct_variant_data = item. expect_struct ( ) . 2 ;
1571
1576
for field_def in struct_variant_data. fields ( ) . iter ( ) . skip ( 1 ) {
1572
1577
// Struct fields (after the first field) are checked for the
1573
1578
// power alignment rule, as fields after the first are likely
1574
1579
// to be the fields that are misaligned.
1575
1580
let def_id = field_def. def_id ;
1576
- let ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
1581
+ let ty = cx . tcx . type_of ( def_id) . instantiate_identity ( ) ;
1577
1582
if Self :: check_arg_for_power_alignment ( cx, ty) {
1578
1583
cx. emit_span_lint ( USES_POWER_ALIGNMENT , field_def. span , UsesPowerAlignment ) ;
1579
1584
}
0 commit comments