@@ -80,6 +80,20 @@ pub enum PredicateFilter {
8080 SelfAndAssociatedTypeBounds ,
8181}
8282
83+ #[ derive( Debug ) ]
84+ pub enum RegionInferReason < ' a > {
85+ /// Lifetime on a trait object behind a reference.
86+ /// This allows inferring information from the reference.
87+ BorrowedObjectLifetimeDefault ,
88+ /// A trait object's lifetime.
89+ ObjectLifetimeDefault ,
90+ /// Generic lifetime parameter
91+ Param ( & ' a ty:: GenericParamDef ) ,
92+ RegionPredicate ,
93+ Reference ,
94+ OutlivesBound ,
95+ }
96+
8397/// A context which can lower type-system entities from the [HIR][hir] to
8498/// the [`rustc_middle::ty`] representation.
8599///
@@ -91,14 +105,7 @@ pub trait HirTyLowerer<'tcx> {
91105 fn item_def_id ( & self ) -> LocalDefId ;
92106
93107 /// Returns the region to use when a lifetime is omitted (and not elided).
94- ///
95- /// The `object_lifetime_default` argument states whether this lifetime is from a reference.
96- fn re_infer (
97- & self ,
98- param : Option < & ty:: GenericParamDef > ,
99- span : Span ,
100- object_lifetime_default : bool ,
101- ) -> ty:: Region < ' tcx > ;
108+ fn re_infer ( & self , span : Span , reason : RegionInferReason < ' _ > ) -> ty:: Region < ' tcx > ;
102109
103110 /// Returns the type to use when a type is omitted.
104111 fn ty_infer ( & self , param : Option < & ty:: GenericParamDef > , span : Span ) -> Ty < ' tcx > ;
@@ -267,7 +274,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
267274 pub fn lower_lifetime (
268275 & self ,
269276 lifetime : & hir:: Lifetime ,
270- def : Option < & ty :: GenericParamDef > ,
277+ reason : RegionInferReason < ' _ > ,
271278 ) -> ty:: Region < ' tcx > {
272279 let tcx = self . tcx ( ) ;
273280 let lifetime_name = |def_id| tcx. hir ( ) . name ( tcx. local_def_id_to_hir_id ( def_id) ) ;
@@ -301,7 +308,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
301308
302309 Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Region :: new_error ( tcx, guar) ,
303310
304- None => self . re_infer ( def , lifetime. ident . span , false ) ,
311+ None => self . re_infer ( lifetime. ident . span , reason ) ,
305312 }
306313 }
307314
@@ -466,7 +473,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
466473
467474 match ( & param. kind , arg) {
468475 ( GenericParamDefKind :: Lifetime , GenericArg :: Lifetime ( lt) ) => {
469- self . lowerer . lower_lifetime ( lt, Some ( param) ) . into ( )
476+ self . lowerer . lower_lifetime ( lt, RegionInferReason :: Param ( param) ) . into ( )
470477 }
471478 ( & GenericParamDefKind :: Type { has_default, .. } , GenericArg :: Type ( ty) ) => {
472479 handle_ty_args ( has_default, ty)
@@ -509,7 +516,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
509516 }
510517 match param. kind {
511518 GenericParamDefKind :: Lifetime => {
512- self . lowerer . re_infer ( Some ( param ) , self . span , false ) . into ( )
519+ self . lowerer . re_infer ( self . span , RegionInferReason :: Param ( param ) ) . into ( )
513520 }
514521 GenericParamDefKind :: Type { has_default, .. } => {
515522 if !infer_args && has_default {
@@ -2041,7 +2048,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20412048 hir:: TyKind :: Slice ( ty) => Ty :: new_slice ( tcx, self . lower_ty ( ty) ) ,
20422049 hir:: TyKind :: Ptr ( mt) => Ty :: new_ptr ( tcx, self . lower_ty ( mt. ty ) , mt. mutbl ) ,
20432050 hir:: TyKind :: Ref ( region, mt) => {
2044- let r = self . lower_lifetime ( region, None ) ;
2051+ let r = self . lower_lifetime ( region, RegionInferReason :: Reference ) ;
20452052 debug ! ( ?r) ;
20462053 let t = self . lower_ty_common ( mt. ty , true , false ) ;
20472054 Ty :: new_ref ( tcx, r, t, mt. mutbl )
@@ -2270,7 +2277,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22702277 & lifetimes[ i]
22712278 )
22722279 } ;
2273- self . lower_lifetime ( lifetime, None ) . into ( )
2280+ self . lower_lifetime ( lifetime, RegionInferReason :: Param ( & param ) ) . into ( )
22742281 } else {
22752282 tcx. mk_param_from_def ( param)
22762283 }
0 commit comments