@@ -1141,14 +1141,6 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
1141
1141
[ var_one, var_two] => match ( & var_one. fields . raw [ ..] , & var_two. fields . raw [ ..] ) {
1142
1142
( [ ] , [ field] ) | ( [ field] , [ ] ) => field. ty ( tcx, args) ,
1143
1143
( [ field1] , [ field2] ) => {
1144
- // TODO: We pass all the checks here although individual enum variants has
1145
- // checks for FFI safety even when niche optimized which needs to be
1146
- // suppressed. for types like `Result<PhantomData<()>, E>`, PhantomData has
1147
- // it's own lint for FFI which needs to be suppressed: `composed only of
1148
- // `PhantomData``. This is true for other custom types as well `struct
1149
- // Example;` which emits `this struct has unspecified layout` and suggests to
1150
- // add `#[repr(C)]` and when that is done, linter emits `this struct has no
1151
- // fields`, all under the `improper_ctypes_definitions` lint group
1152
1144
let ty1 = field1. ty ( tcx, args) ;
1153
1145
let ty2 = field2. ty ( tcx, args) ;
1154
1146
@@ -1245,7 +1237,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1245
1237
args : GenericArgsRef < ' tcx > ,
1246
1238
) -> FfiResult < ' tcx > {
1247
1239
use FfiResult :: * ;
1248
-
1249
1240
let transparent_with_all_zst_fields = if def. repr ( ) . transparent ( ) {
1250
1241
if let Some ( field) = transparent_newtype_field ( self . cx . tcx , variant) {
1251
1242
// Transparent newtypes have at most one non-ZST field which needs to be checked..
@@ -1372,27 +1363,29 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1372
1363
return FfiSafe ;
1373
1364
}
1374
1365
1366
+ if def. is_variant_list_non_exhaustive ( ) && !def. did ( ) . is_local ( ) {
1367
+ return FfiUnsafe {
1368
+ ty,
1369
+ reason : fluent:: lint_improper_ctypes_non_exhaustive,
1370
+ help : None ,
1371
+ } ;
1372
+ }
1373
+
1375
1374
// Check for a repr() attribute to specify the size of the
1376
1375
// discriminant.
1377
1376
if !def. repr ( ) . c ( ) && !def. repr ( ) . transparent ( ) && def. repr ( ) . int . is_none ( )
1378
1377
{
1379
1378
// Special-case types like `Option<extern fn()>` and `Result<extern fn(), ()>`
1380
- if repr_nullable_ptr ( self . cx . tcx , self . cx . param_env , ty , self . mode )
1381
- . is_none ( )
1379
+ if let Some ( ty ) =
1380
+ repr_nullable_ptr ( self . cx . tcx , self . cx . param_env , ty , self . mode )
1382
1381
{
1383
- return FfiUnsafe {
1384
- ty,
1385
- reason : fluent:: lint_improper_ctypes_enum_repr_reason,
1386
- help : Some ( fluent:: lint_improper_ctypes_enum_repr_help) ,
1387
- } ;
1382
+ return self . check_type_for_ffi ( cache, ty) ;
1388
1383
}
1389
- }
1390
1384
1391
- if def. is_variant_list_non_exhaustive ( ) && !def. did ( ) . is_local ( ) {
1392
1385
return FfiUnsafe {
1393
1386
ty,
1394
- reason : fluent:: lint_improper_ctypes_non_exhaustive ,
1395
- help : None ,
1387
+ reason : fluent:: lint_improper_ctypes_enum_repr_reason ,
1388
+ help : Some ( fluent :: lint_improper_ctypes_enum_repr_help ) ,
1396
1389
} ;
1397
1390
}
1398
1391
0 commit comments