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