@@ -966,12 +966,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
966966 args : GenericArgsRef < ' tcx > ,
967967 ) -> FfiResult < ' tcx > {
968968 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 )
975975 }
976976
977977 /// Checks if the given `VariantDef`'s field types are "ffi-safe".
@@ -1320,7 +1320,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
13201320 if let Some ( ty) = self
13211321 . cx
13221322 . tcx
1323- . normalize_erasing_regions ( self . cx . param_env , ty)
1323+ . try_normalize_erasing_regions ( self . cx . param_env , ty)
1324+ . unwrap_or ( ty)
13241325 . visit_with ( & mut ProhibitOpaqueTypes )
13251326 . break_value ( )
13261327 {
@@ -1338,16 +1339,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
13381339 is_static : bool ,
13391340 is_return_type : bool ,
13401341 ) {
1341- // We have to check for opaque types before `normalize_erasing_regions`,
1342- // which will replace opaque types with their underlying concrete type.
13431342 if self . check_for_opaque_ty ( sp, ty) {
13441343 // We've already emitted an error due to an opaque type.
13451344 return ;
13461345 }
13471346
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) ;
13511348
13521349 // C doesn't really support passing arrays by value - the only way to pass an array by value
13531350 // is through a struct. So, first test that the top level isn't an array, and then
0 commit comments