@@ -878,39 +878,39 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
878878 ) -> FfiResult < ' tcx > {
879879 use FfiResult :: * ;
880880
881- if def. repr ( ) . transparent ( ) {
881+ let transparent_safety = def. repr ( ) . transparent ( ) . then ( || {
882882 // Can assume that at most one field is not a ZST, so only check
883883 // that field's type for FFI-safety.
884884 if let Some ( field) = transparent_newtype_field ( self . cx . tcx , variant) {
885- self . check_field_type_for_ffi ( cache, field, substs)
885+ return self . check_field_type_for_ffi ( cache, field, substs) ;
886886 } else {
887887 // All fields are ZSTs; this means that the type should behave
888- // like (), which is FFI-unsafe
888+ // like (), which is FFI-unsafe... except if all fields are PhantomData,
889+ // which is tested for below
889890 FfiUnsafe { ty, reason : fluent:: lint_improper_ctypes_struct_zst, help : None }
890891 }
891- } else {
892- // We can't completely trust repr(C) markings; make sure the fields are
893- // actually safe.
894- let mut all_phantom = !variant. fields . is_empty ( ) ;
895- for field in & variant. fields {
896- match self . check_field_type_for_ffi ( cache, & field, substs) {
897- FfiSafe => {
898- all_phantom = false ;
899- }
900- FfiPhantom ( ..) if def. is_enum ( ) => {
901- return FfiUnsafe {
902- ty,
903- reason : fluent:: lint_improper_ctypes_enum_phantomdata,
904- help : None ,
905- } ;
906- }
907- FfiPhantom ( ..) => { }
908- r => return r,
892+ } ) ;
893+ // We can't completely trust repr(C) markings; make sure the fields are
894+ // actually safe.
895+ let mut all_phantom = !variant. fields . is_empty ( ) ;
896+ for field in & variant. fields {
897+ match self . check_field_type_for_ffi ( cache, & field, substs) {
898+ FfiSafe => {
899+ all_phantom = false ;
909900 }
901+ FfiPhantom ( ..) if !def. repr ( ) . transparent ( ) && def. is_enum ( ) => {
902+ return FfiUnsafe {
903+ ty,
904+ reason : fluent:: lint_improper_ctypes_enum_phantomdata,
905+ help : None ,
906+ } ;
907+ }
908+ FfiPhantom ( ..) => { }
909+ r => return transparent_safety. unwrap_or ( r) ,
910910 }
911-
912- if all_phantom { FfiPhantom ( ty) } else { FfiSafe }
913911 }
912+
913+ if all_phantom { FfiPhantom ( ty) } else { transparent_safety. unwrap_or ( FfiSafe ) }
914914 }
915915
916916 /// Checks if the given type is "ffi-safe" (has a stable, well-defined
0 commit comments