@@ -26,7 +26,7 @@ use rustc_target::spec::abi::Abi;
2626use smallvec:: SmallVec ;
2727use std:: fmt;
2828
29- #[ derive( Copy , Clone , Encodable , HashStable_Generic ) ]
29+ #[ derive( Debug , Copy , Clone , Encodable , HashStable_Generic ) ]
3030pub struct Lifetime {
3131 pub hir_id : HirId ,
3232 pub span : Span ,
@@ -60,7 +60,7 @@ pub enum ParamName {
6060 /// ```
6161 /// where `'f` is something like `Fresh(0)`. The indices are
6262 /// unique per impl, but not necessarily continuous.
63- Fresh ( LocalDefId ) ,
63+ Fresh ,
6464
6565 /// Indicates an illegal name was given and an error has been
6666 /// reported (so we should squelch other derived errors). Occurs
@@ -72,9 +72,7 @@ impl ParamName {
7272 pub fn ident ( & self ) -> Ident {
7373 match * self {
7474 ParamName :: Plain ( ident) => ident,
75- ParamName :: Fresh ( _) | ParamName :: Error => {
76- Ident :: with_dummy_span ( kw:: UnderscoreLifetime )
77- }
75+ ParamName :: Fresh | ParamName :: Error => Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ,
7876 }
7977 }
8078
@@ -90,7 +88,7 @@ impl ParamName {
9088#[ derive( HashStable_Generic ) ]
9189pub enum LifetimeName {
9290 /// User-given names or fresh (synthetic) names.
93- Param ( ParamName ) ,
91+ Param ( LocalDefId , ParamName ) ,
9492
9593 /// User wrote nothing (e.g., the lifetime in `&u32`).
9694 Implicit ,
@@ -127,7 +125,7 @@ impl LifetimeName {
127125 | LifetimeName :: Error => Ident :: empty ( ) ,
128126 LifetimeName :: Underscore => Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ,
129127 LifetimeName :: Static => Ident :: with_dummy_span ( kw:: StaticLifetime ) ,
130- LifetimeName :: Param ( param_name) => param_name. ident ( ) ,
128+ LifetimeName :: Param ( _ , param_name) => param_name. ident ( ) ,
131129 }
132130 }
133131
@@ -136,9 +134,9 @@ impl LifetimeName {
136134 LifetimeName :: ImplicitObjectLifetimeDefault
137135 | LifetimeName :: Implicit
138136 | LifetimeName :: Underscore
139- | LifetimeName :: Param ( ParamName :: Fresh ( _ ) )
137+ | LifetimeName :: Param ( _ , ParamName :: Fresh )
140138 | LifetimeName :: Error => true ,
141- LifetimeName :: Static | LifetimeName :: Param ( _ ) => false ,
139+ LifetimeName :: Static | LifetimeName :: Param ( .. ) => false ,
142140 }
143141 }
144142
@@ -148,12 +146,12 @@ impl LifetimeName {
148146 | LifetimeName :: Implicit
149147 | LifetimeName :: Underscore => true ,
150148
151- // It might seem surprising that `Fresh(_) ` counts as
149+ // It might seem surprising that `Fresh` counts as
152150 // *not* elided -- but this is because, as far as the code
153- // in the compiler is concerned -- `Fresh(_) ` variants act
151+ // in the compiler is concerned -- `Fresh` variants act
154152 // equivalently to "some fresh name". They correspond to
155153 // early-bound regions on an impl, in other words.
156- LifetimeName :: Error | LifetimeName :: Param ( _ ) | LifetimeName :: Static => false ,
154+ LifetimeName :: Error | LifetimeName :: Param ( .. ) | LifetimeName :: Static => false ,
157155 }
158156 }
159157
@@ -163,8 +161,8 @@ impl LifetimeName {
163161
164162 pub fn normalize_to_macros_2_0 ( & self ) -> LifetimeName {
165163 match * self {
166- LifetimeName :: Param ( param_name) => {
167- LifetimeName :: Param ( param_name. normalize_to_macros_2_0 ( ) )
164+ LifetimeName :: Param ( def_id , param_name) => {
165+ LifetimeName :: Param ( def_id , param_name. normalize_to_macros_2_0 ( ) )
168166 }
169167 lifetime_name => lifetime_name,
170168 }
@@ -177,12 +175,6 @@ impl fmt::Display for Lifetime {
177175 }
178176}
179177
180- impl fmt:: Debug for Lifetime {
181- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
182- write ! ( f, "lifetime({}: {})" , self . hir_id, self . name. ident( ) )
183- }
184- }
185-
186178impl Lifetime {
187179 pub fn is_elided ( & self ) -> bool {
188180 self . name . is_elided ( )
@@ -628,6 +620,16 @@ impl<'hir> Generics<'hir> {
628620 } )
629621 }
630622
623+ pub fn outlives_for_param (
624+ & self ,
625+ param_def_id : LocalDefId ,
626+ ) -> impl Iterator < Item = & WhereRegionPredicate < ' _ > > {
627+ self . predicates . iter ( ) . filter_map ( move |pred| match pred {
628+ WherePredicate :: RegionPredicate ( rp) if rp. is_param_bound ( param_def_id) => Some ( rp) ,
629+ _ => None ,
630+ } )
631+ }
632+
631633 pub fn bounds_span_for_suggestions ( & self , param_def_id : LocalDefId ) -> Option < Span > {
632634 self . bounds_for_param ( param_def_id) . flat_map ( |bp| bp. bounds . iter ( ) . rev ( ) ) . find_map (
633635 |bound| {
@@ -769,6 +771,16 @@ pub struct WhereRegionPredicate<'hir> {
769771 pub bounds : GenericBounds < ' hir > ,
770772}
771773
774+ impl < ' hir > WhereRegionPredicate < ' hir > {
775+ /// Returns `true` if `param_def_id` matches the `lifetime` of this predicate.
776+ pub fn is_param_bound ( & self , param_def_id : LocalDefId ) -> bool {
777+ match self . lifetime . name {
778+ LifetimeName :: Param ( id, _) => id == param_def_id,
779+ _ => false ,
780+ }
781+ }
782+ }
783+
772784/// An equality predicate (e.g., `T = int`); currently unsupported.
773785#[ derive( Debug , HashStable_Generic ) ]
774786pub struct WhereEqPredicate < ' hir > {
0 commit comments