@@ -2883,22 +2883,45 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2883
2883
hir:: TyKind :: BareFn ( bf) => {
2884
2884
require_c_abi_if_c_variadic ( tcx, bf. decl , bf. abi , ast_ty. span ) ;
2885
2885
2886
- tcx. mk_fn_ptr ( self . ty_of_fn (
2886
+ let fn_ptr_ty = tcx. mk_fn_ptr ( self . ty_of_fn (
2887
2887
ast_ty. hir_id ,
2888
2888
bf. unsafety ,
2889
2889
bf. abi ,
2890
2890
bf. decl ,
2891
2891
None ,
2892
2892
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
+ }
2894
2902
}
2895
2903
hir:: TyKind :: TraitObject ( bounds, lifetime, repr) => {
2896
2904
self . maybe_lint_bare_trait ( ast_ty, in_path) ;
2897
2905
let repr = match repr {
2898
2906
TraitObjectSyntax :: Dyn | TraitObjectSyntax :: None => ty:: Dyn ,
2899
2907
TraitObjectSyntax :: DynStar => ty:: DynStar ,
2900
2908
} ;
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
+ }
2902
2925
}
2903
2926
hir:: TyKind :: Path ( hir:: QPath :: Resolved ( maybe_qself, path) ) => {
2904
2927
debug ! ( ?maybe_qself, ?path) ;
@@ -3359,3 +3382,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
3359
3382
}
3360
3383
}
3361
3384
}
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