@@ -80,6 +80,20 @@ pub enum PredicateFilter {
80
80
SelfAndAssociatedTypeBounds ,
81
81
}
82
82
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
+
83
97
/// A context which can lower type-system entities from the [HIR][hir] to
84
98
/// the [`rustc_middle::ty`] representation.
85
99
///
@@ -91,14 +105,7 @@ pub trait HirTyLowerer<'tcx> {
91
105
fn item_def_id ( & self ) -> LocalDefId ;
92
106
93
107
/// 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 > ;
102
109
103
110
/// Returns the type to use when a type is omitted.
104
111
fn ty_infer ( & self , param : Option < & ty:: GenericParamDef > , span : Span ) -> Ty < ' tcx > ;
@@ -267,7 +274,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
267
274
pub fn lower_lifetime (
268
275
& self ,
269
276
lifetime : & hir:: Lifetime ,
270
- def : Option < & ty :: GenericParamDef > ,
277
+ reason : RegionInferReason < ' _ > ,
271
278
) -> ty:: Region < ' tcx > {
272
279
let tcx = self . tcx ( ) ;
273
280
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> + '_ {
301
308
302
309
Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Region :: new_error ( tcx, guar) ,
303
310
304
- None => self . re_infer ( def , lifetime. ident . span , false ) ,
311
+ None => self . re_infer ( lifetime. ident . span , reason ) ,
305
312
}
306
313
}
307
314
@@ -466,7 +473,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
466
473
467
474
match ( & param. kind , arg) {
468
475
( GenericParamDefKind :: Lifetime , GenericArg :: Lifetime ( lt) ) => {
469
- self . lowerer . lower_lifetime ( lt, Some ( param) ) . into ( )
476
+ self . lowerer . lower_lifetime ( lt, RegionInferReason :: Param ( param) ) . into ( )
470
477
}
471
478
( & GenericParamDefKind :: Type { has_default, .. } , GenericArg :: Type ( ty) ) => {
472
479
handle_ty_args ( has_default, ty)
@@ -509,7 +516,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
509
516
}
510
517
match param. kind {
511
518
GenericParamDefKind :: Lifetime => {
512
- self . lowerer . re_infer ( Some ( param ) , self . span , false ) . into ( )
519
+ self . lowerer . re_infer ( self . span , RegionInferReason :: Param ( param ) ) . into ( )
513
520
}
514
521
GenericParamDefKind :: Type { has_default, .. } => {
515
522
if !infer_args && has_default {
@@ -2041,7 +2048,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2041
2048
hir:: TyKind :: Slice ( ty) => Ty :: new_slice ( tcx, self . lower_ty ( ty) ) ,
2042
2049
hir:: TyKind :: Ptr ( mt) => Ty :: new_ptr ( tcx, self . lower_ty ( mt. ty ) , mt. mutbl ) ,
2043
2050
hir:: TyKind :: Ref ( region, mt) => {
2044
- let r = self . lower_lifetime ( region, None ) ;
2051
+ let r = self . lower_lifetime ( region, RegionInferReason :: Reference ) ;
2045
2052
debug ! ( ?r) ;
2046
2053
let t = self . lower_ty_common ( mt. ty , true , false ) ;
2047
2054
Ty :: new_ref ( tcx, r, t, mt. mutbl )
@@ -2270,7 +2277,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2270
2277
& lifetimes[ i]
2271
2278
)
2272
2279
} ;
2273
- self . lower_lifetime ( lifetime, None ) . into ( )
2280
+ self . lower_lifetime ( lifetime, RegionInferReason :: Param ( & param ) ) . into ( )
2274
2281
} else {
2275
2282
tcx. mk_param_from_def ( param)
2276
2283
}
0 commit comments