@@ -963,12 +963,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
963
963
substs : SubstsRef < ' tcx > ,
964
964
) -> FfiResult < ' tcx > {
965
965
let field_ty = field. ty ( self . cx . tcx , substs) ;
966
- if field_ty. has_opaque_types ( ) {
967
- self . check_type_for_ffi ( cache , field_ty )
968
- } else {
969
- let field_ty = self . cx . tcx . normalize_erasing_regions ( self . cx . param_env , field_ty) ;
970
- self . check_type_for_ffi ( cache , field_ty)
971
- }
966
+ let field_ty = self
967
+ . cx
968
+ . tcx
969
+ . try_normalize_erasing_regions ( self . cx . param_env , field_ty)
970
+ . unwrap_or ( field_ty) ;
971
+ self . check_type_for_ffi ( cache , field_ty )
972
972
}
973
973
974
974
/// Checks if the given `VariantDef`'s field types are "ffi-safe".
@@ -1315,7 +1315,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1315
1315
if let Some ( ty) = self
1316
1316
. cx
1317
1317
. tcx
1318
- . normalize_erasing_regions ( self . cx . param_env , ty)
1318
+ . try_normalize_erasing_regions ( self . cx . param_env , ty)
1319
+ . unwrap_or ( ty)
1319
1320
. visit_with ( & mut ProhibitOpaqueTypes )
1320
1321
. break_value ( )
1321
1322
{
@@ -1333,16 +1334,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
1333
1334
is_static : bool ,
1334
1335
is_return_type : bool ,
1335
1336
) {
1336
- // We have to check for opaque types before `normalize_erasing_regions`,
1337
- // which will replace opaque types with their underlying concrete type.
1338
1337
if self . check_for_opaque_ty ( sp, ty) {
1339
1338
// We've already emitted an error due to an opaque type.
1340
1339
return ;
1341
1340
}
1342
1341
1343
- // it is only OK to use this function because extern fns cannot have
1344
- // any generic types right now:
1345
- let ty = self . cx . tcx . normalize_erasing_regions ( self . cx . param_env , ty) ;
1342
+ let ty = self . cx . tcx . try_normalize_erasing_regions ( self . cx . param_env , ty) . unwrap_or ( ty) ;
1346
1343
1347
1344
// C doesn't really support passing arrays by value - the only way to pass an array by value
1348
1345
// is through a struct. So, first test that the top level isn't an array, and then
0 commit comments