@@ -291,6 +291,21 @@ fn late_arg_as_bound_arg<'tcx>(
291
291
}
292
292
}
293
293
294
+ /// Turn a [`ty::GenericParamDef`] into a bound arg. Generally, this should only
295
+ /// be used when turning early-bound vars into late-bound vars when lowering
296
+ /// return type notation.
297
+ fn generic_param_def_as_bound_arg ( param : & ty:: GenericParamDef ) -> ty:: BoundVariableKind {
298
+ match param. kind {
299
+ ty:: GenericParamDefKind :: Lifetime => {
300
+ ty:: BoundVariableKind :: Region ( ty:: BoundRegionKind :: BrNamed ( param. def_id , param. name ) )
301
+ }
302
+ ty:: GenericParamDefKind :: Type { .. } => {
303
+ ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( param. def_id , param. name ) )
304
+ }
305
+ ty:: GenericParamDefKind :: Const { .. } => ty:: BoundVariableKind :: Const ,
306
+ }
307
+ }
308
+
294
309
impl < ' a , ' tcx > BoundVarContext < ' a , ' tcx > {
295
310
/// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref.
296
311
fn poly_trait_ref_binder_info ( & mut self ) -> ( Vec < ty:: BoundVariableKind > , BinderScopeType ) {
@@ -1628,17 +1643,13 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1628
1643
constraint. ident ,
1629
1644
ty:: AssocKind :: Fn ,
1630
1645
) {
1631
- bound_vars. extend ( self . tcx . generics_of ( assoc_fn. def_id ) . own_params . iter ( ) . map (
1632
- |param| match param. kind {
1633
- ty:: GenericParamDefKind :: Lifetime => ty:: BoundVariableKind :: Region (
1634
- ty:: BoundRegionKind :: BrNamed ( param. def_id , param. name ) ,
1635
- ) ,
1636
- ty:: GenericParamDefKind :: Type { .. } => ty:: BoundVariableKind :: Ty (
1637
- ty:: BoundTyKind :: Param ( param. def_id , param. name ) ,
1638
- ) ,
1639
- ty:: GenericParamDefKind :: Const { .. } => ty:: BoundVariableKind :: Const ,
1640
- } ,
1641
- ) ) ;
1646
+ bound_vars. extend (
1647
+ self . tcx
1648
+ . generics_of ( assoc_fn. def_id )
1649
+ . own_params
1650
+ . iter ( )
1651
+ . map ( |param| generic_param_def_as_bound_arg ( param) ) ,
1652
+ ) ;
1642
1653
bound_vars. extend (
1643
1654
self . tcx . fn_sig ( assoc_fn. def_id ) . instantiate_identity ( ) . bound_vars ( ) ,
1644
1655
) ;
@@ -1957,17 +1968,13 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1957
1968
// Append the early-bound vars on the function, and then the late-bound ones.
1958
1969
// We actually turn type parameters into higher-ranked types here, but we
1959
1970
// deny them later in HIR lowering.
1960
- bound_vars. extend ( self . tcx . generics_of ( item_def_id) . own_params . iter ( ) . map ( |param| {
1961
- match param. kind {
1962
- ty:: GenericParamDefKind :: Lifetime => ty:: BoundVariableKind :: Region (
1963
- ty:: BoundRegionKind :: BrNamed ( param. def_id , param. name ) ,
1964
- ) ,
1965
- ty:: GenericParamDefKind :: Type { .. } => {
1966
- ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( param. def_id , param. name ) )
1967
- }
1968
- ty:: GenericParamDefKind :: Const { .. } => ty:: BoundVariableKind :: Const ,
1969
- }
1970
- } ) ) ;
1971
+ bound_vars. extend (
1972
+ self . tcx
1973
+ . generics_of ( item_def_id)
1974
+ . own_params
1975
+ . iter ( )
1976
+ . map ( |param| generic_param_def_as_bound_arg ( param) ) ,
1977
+ ) ;
1971
1978
bound_vars. extend ( self . tcx . fn_sig ( item_def_id) . instantiate_identity ( ) . bound_vars ( ) ) ;
1972
1979
1973
1980
// SUBTLE: Stash the old bound vars onto the *item segment* before appending
0 commit comments