@@ -26,7 +26,7 @@ use rustc_target::spec::abi::Abi;
26
26
use smallvec:: SmallVec ;
27
27
use std:: fmt;
28
28
29
- #[ derive( Copy , Clone , Encodable , HashStable_Generic ) ]
29
+ #[ derive( Debug , Copy , Clone , Encodable , HashStable_Generic ) ]
30
30
pub struct Lifetime {
31
31
pub hir_id : HirId ,
32
32
pub span : Span ,
@@ -60,7 +60,7 @@ pub enum ParamName {
60
60
/// ```
61
61
/// where `'f` is something like `Fresh(0)`. The indices are
62
62
/// unique per impl, but not necessarily continuous.
63
- Fresh ( LocalDefId ) ,
63
+ Fresh ,
64
64
65
65
/// Indicates an illegal name was given and an error has been
66
66
/// reported (so we should squelch other derived errors). Occurs
@@ -72,9 +72,7 @@ impl ParamName {
72
72
pub fn ident ( & self ) -> Ident {
73
73
match * self {
74
74
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 ) ,
78
76
}
79
77
}
80
78
@@ -90,7 +88,7 @@ impl ParamName {
90
88
#[ derive( HashStable_Generic ) ]
91
89
pub enum LifetimeName {
92
90
/// User-given names or fresh (synthetic) names.
93
- Param ( ParamName ) ,
91
+ Param ( LocalDefId , ParamName ) ,
94
92
95
93
/// User wrote nothing (e.g., the lifetime in `&u32`).
96
94
Implicit ,
@@ -127,7 +125,7 @@ impl LifetimeName {
127
125
| LifetimeName :: Error => Ident :: empty ( ) ,
128
126
LifetimeName :: Underscore => Ident :: with_dummy_span ( kw:: UnderscoreLifetime ) ,
129
127
LifetimeName :: Static => Ident :: with_dummy_span ( kw:: StaticLifetime ) ,
130
- LifetimeName :: Param ( param_name) => param_name. ident ( ) ,
128
+ LifetimeName :: Param ( _ , param_name) => param_name. ident ( ) ,
131
129
}
132
130
}
133
131
@@ -136,9 +134,9 @@ impl LifetimeName {
136
134
LifetimeName :: ImplicitObjectLifetimeDefault
137
135
| LifetimeName :: Implicit
138
136
| LifetimeName :: Underscore
139
- | LifetimeName :: Param ( ParamName :: Fresh ( _ ) )
137
+ | LifetimeName :: Param ( _ , ParamName :: Fresh )
140
138
| LifetimeName :: Error => true ,
141
- LifetimeName :: Static | LifetimeName :: Param ( _ ) => false ,
139
+ LifetimeName :: Static | LifetimeName :: Param ( .. ) => false ,
142
140
}
143
141
}
144
142
@@ -148,12 +146,12 @@ impl LifetimeName {
148
146
| LifetimeName :: Implicit
149
147
| LifetimeName :: Underscore => true ,
150
148
151
- // It might seem surprising that `Fresh(_) ` counts as
149
+ // It might seem surprising that `Fresh` counts as
152
150
// *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
154
152
// equivalently to "some fresh name". They correspond to
155
153
// 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 ,
157
155
}
158
156
}
159
157
@@ -163,8 +161,8 @@ impl LifetimeName {
163
161
164
162
pub fn normalize_to_macros_2_0 ( & self ) -> LifetimeName {
165
163
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 ( ) )
168
166
}
169
167
lifetime_name => lifetime_name,
170
168
}
@@ -177,12 +175,6 @@ impl fmt::Display for Lifetime {
177
175
}
178
176
}
179
177
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
-
186
178
impl Lifetime {
187
179
pub fn is_elided ( & self ) -> bool {
188
180
self . name . is_elided ( )
@@ -628,6 +620,16 @@ impl<'hir> Generics<'hir> {
628
620
} )
629
621
}
630
622
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
+
631
633
pub fn bounds_span_for_suggestions ( & self , param_def_id : LocalDefId ) -> Option < Span > {
632
634
self . bounds_for_param ( param_def_id) . flat_map ( |bp| bp. bounds . iter ( ) . rev ( ) ) . find_map (
633
635
|bound| {
@@ -769,6 +771,16 @@ pub struct WhereRegionPredicate<'hir> {
769
771
pub bounds : GenericBounds < ' hir > ,
770
772
}
771
773
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
+
772
784
/// An equality predicate (e.g., `T = int`); currently unsupported.
773
785
#[ derive( Debug , HashStable_Generic ) ]
774
786
pub struct WhereEqPredicate < ' hir > {
0 commit comments