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