@@ -2561,27 +2561,29 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25612561 // reject function types that violate cmse ABI requirements
25622562 cmse:: validate_cmse_abi ( self . tcx ( ) , self . dcx ( ) , hir_id, abi, bare_fn_ty) ;
25632563
2564- // Find any late-bound regions declared in return type that do
2565- // not appear in the arguments. These are not well-formed.
2566- //
2567- // Example:
2568- // for<'a> fn() -> &'a str <-- 'a is bad
2569- // for<'a> fn(&'a String) -> &'a str <-- 'a is ok
2570- let inputs = bare_fn_ty. inputs ( ) ;
2571- let late_bound_in_args =
2572- tcx. collect_constrained_late_bound_regions ( inputs. map_bound ( |i| i. to_owned ( ) ) ) ;
2573- let output = bare_fn_ty. output ( ) ;
2574- let late_bound_in_ret = tcx. collect_referenced_late_bound_regions ( output) ;
2575-
2576- self . validate_late_bound_regions ( late_bound_in_args, late_bound_in_ret, |br_name| {
2577- struct_span_code_err ! (
2578- self . dcx( ) ,
2579- decl. output. span( ) ,
2580- E0581 ,
2581- "return type references {}, which is not constrained by the fn input types" ,
2582- br_name
2583- )
2584- } ) ;
2564+ if !bare_fn_ty. references_error ( ) {
2565+ // Find any late-bound regions declared in return type that do
2566+ // not appear in the arguments. These are not well-formed.
2567+ //
2568+ // Example:
2569+ // for<'a> fn() -> &'a str <-- 'a is bad
2570+ // for<'a> fn(&'a String) -> &'a str <-- 'a is ok
2571+ let inputs = bare_fn_ty. inputs ( ) ;
2572+ let late_bound_in_args =
2573+ tcx. collect_constrained_late_bound_regions ( inputs. map_bound ( |i| i. to_owned ( ) ) ) ;
2574+ let output = bare_fn_ty. output ( ) ;
2575+ let late_bound_in_ret = tcx. collect_referenced_late_bound_regions ( output) ;
2576+
2577+ self . validate_late_bound_regions ( late_bound_in_args, late_bound_in_ret, |br_name| {
2578+ struct_span_code_err ! (
2579+ self . dcx( ) ,
2580+ decl. output. span( ) ,
2581+ E0581 ,
2582+ "return type references {}, which is not constrained by the fn input types" ,
2583+ br_name
2584+ )
2585+ } ) ;
2586+ }
25852587
25862588 bare_fn_ty
25872589 }
0 commit comments