@@ -1096,14 +1096,6 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
1096
1096
[ var_one, var_two] => match ( & var_one. fields . raw [ ..] , & var_two. fields . raw [ ..] ) {
1097
1097
( [ ] , [ field] ) | ( [ field] , [ ] ) => field. ty ( tcx, args) ,
1098
1098
( [ field1] , [ field2] ) => {
1099
- // TODO: We pass all the checks here although individual enum variants has
1100
- // checks for FFI safety even when niche optimized which needs to be
1101
- // suppressed. for types like `Result<PhantomData<()>, E>`, PhantomData has
1102
- // it's own lint for FFI which needs to be suppressed: `composed only of
1103
- // `PhantomData``. This is true for other custom types as well `struct
1104
- // Example;` which emits `this struct has unspecified layout` and suggests to
1105
- // add `#[repr(C)]` and when that is done, linter emits `this struct has no
1106
- // fields`, all under the `improper_ctypes_definitions` lint group
1107
1099
let ty1 = field1. ty ( tcx, args) ;
1108
1100
let ty2 = field2. ty ( tcx, args) ;
1109
1101
@@ -1200,7 +1192,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1200
1192
args : GenericArgsRef < ' tcx > ,
1201
1193
) -> FfiResult < ' tcx > {
1202
1194
use FfiResult :: * ;
1203
-
1204
1195
let transparent_with_all_zst_fields = if def. repr ( ) . transparent ( ) {
1205
1196
if let Some ( field) = transparent_newtype_field ( self . cx . tcx , variant) {
1206
1197
// Transparent newtypes have at most one non-ZST field which needs to be checked..
@@ -1327,27 +1318,29 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1327
1318
return FfiSafe ;
1328
1319
}
1329
1320
1321
+ if def. is_variant_list_non_exhaustive ( ) && !def. did ( ) . is_local ( ) {
1322
+ return FfiUnsafe {
1323
+ ty,
1324
+ reason : fluent:: lint_improper_ctypes_non_exhaustive,
1325
+ help : None ,
1326
+ } ;
1327
+ }
1328
+
1330
1329
// Check for a repr() attribute to specify the size of the
1331
1330
// discriminant.
1332
1331
if !def. repr ( ) . c ( ) && !def. repr ( ) . transparent ( ) && def. repr ( ) . int . is_none ( )
1333
1332
{
1334
1333
// Special-case types like `Option<extern fn()>` and `Result<extern fn(), ()>`
1335
- if repr_nullable_ptr ( self . cx . tcx , self . cx . param_env , ty , self . mode )
1336
- . is_none ( )
1334
+ if let Some ( ty ) =
1335
+ repr_nullable_ptr ( self . cx . tcx , self . cx . param_env , ty , self . mode )
1337
1336
{
1338
- return FfiUnsafe {
1339
- ty,
1340
- reason : fluent:: lint_improper_ctypes_enum_repr_reason,
1341
- help : Some ( fluent:: lint_improper_ctypes_enum_repr_help) ,
1342
- } ;
1337
+ return self . check_type_for_ffi ( cache, ty) ;
1343
1338
}
1344
- }
1345
1339
1346
- if def. is_variant_list_non_exhaustive ( ) && !def. did ( ) . is_local ( ) {
1347
1340
return FfiUnsafe {
1348
1341
ty,
1349
- reason : fluent:: lint_improper_ctypes_non_exhaustive ,
1350
- help : None ,
1342
+ reason : fluent:: lint_improper_ctypes_enum_repr_reason ,
1343
+ help : Some ( fluent :: lint_improper_ctypes_enum_repr_help ) ,
1351
1344
} ;
1352
1345
}
1353
1346
0 commit comments