@@ -2883,22 +2883,45 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28832883 hir:: TyKind :: BareFn ( bf) => {
28842884 require_c_abi_if_c_variadic ( tcx, bf. decl , bf. abi , ast_ty. span ) ;
28852885
2886- tcx. mk_fn_ptr ( self . ty_of_fn (
2886+ let fn_ptr_ty = tcx. mk_fn_ptr ( self . ty_of_fn (
28872887 ast_ty. hir_id ,
28882888 bf. unsafety ,
28892889 bf. abi ,
28902890 bf. decl ,
28912891 None ,
28922892 Some ( ast_ty) ,
2893- ) )
2893+ ) ) ;
2894+
2895+ if let Some ( guar) =
2896+ deny_non_region_late_bound ( tcx, bf. generic_params , "function pointer" )
2897+ {
2898+ tcx. ty_error_with_guaranteed ( guar)
2899+ } else {
2900+ fn_ptr_ty
2901+ }
28942902 }
28952903 hir:: TyKind :: TraitObject ( bounds, lifetime, repr) => {
28962904 self . maybe_lint_bare_trait ( ast_ty, in_path) ;
28972905 let repr = match repr {
28982906 TraitObjectSyntax :: Dyn | TraitObjectSyntax :: None => ty:: Dyn ,
28992907 TraitObjectSyntax :: DynStar => ty:: DynStar ,
29002908 } ;
2901- self . conv_object_ty_poly_trait_ref ( ast_ty. span , bounds, lifetime, borrowed, repr)
2909+
2910+ let object_ty = self . conv_object_ty_poly_trait_ref (
2911+ ast_ty. span ,
2912+ bounds,
2913+ lifetime,
2914+ borrowed,
2915+ repr,
2916+ ) ;
2917+
2918+ if let Some ( guar) = bounds. iter ( ) . find_map ( |trait_ref| {
2919+ deny_non_region_late_bound ( tcx, trait_ref. bound_generic_params , "trait object" )
2920+ } ) {
2921+ tcx. ty_error_with_guaranteed ( guar)
2922+ } else {
2923+ object_ty
2924+ }
29022925 }
29032926 hir:: TyKind :: Path ( hir:: QPath :: Resolved ( maybe_qself, path) ) => {
29042927 debug ! ( ?maybe_qself, ?path) ;
@@ -3359,3 +3382,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
33593382 }
33603383 }
33613384}
3385+
3386+ fn deny_non_region_late_bound (
3387+ tcx : TyCtxt < ' _ > ,
3388+ params : & [ hir:: GenericParam < ' _ > ] ,
3389+ where_ : & str ,
3390+ ) -> Option < ErrorGuaranteed > {
3391+ params. iter ( ) . find_map ( |bad_param| {
3392+ let what = match bad_param. kind {
3393+ hir:: GenericParamKind :: Type { .. } => "type" ,
3394+ hir:: GenericParamKind :: Const { .. } => "const" ,
3395+ hir:: GenericParamKind :: Lifetime { .. } => return None ,
3396+ } ;
3397+
3398+ let mut diag = tcx. sess . struct_span_err (
3399+ bad_param. span ,
3400+ format ! ( "late-bound {what} parameter not allowed on {where_} types" ) ,
3401+ ) ;
3402+
3403+ Some ( if tcx. features ( ) . non_lifetime_binders { diag. emit ( ) } else { diag. delay_as_bug ( ) } )
3404+ } )
3405+ }
0 commit comments