@@ -89,6 +89,16 @@ impl<'a> FnKind<'a> {
89
89
}
90
90
}
91
91
92
+ #[ derive( Copy , Clone , Debug ) ]
93
+ pub enum LifetimeCtxt {
94
+ /// Appears in a reference type.
95
+ Rptr ,
96
+ /// Appears as a bound on a type or another lifetime.
97
+ Bound ,
98
+ /// Appears as a generic argument.
99
+ GenericArg ,
100
+ }
101
+
92
102
/// Each method of the `Visitor` trait is a hook to be potentially
93
103
/// overridden. Each method's default implementation recursively visits
94
104
/// the substructure of the input via the corresponding `walk` method;
@@ -184,7 +194,7 @@ pub trait Visitor<'ast>: Sized {
184
194
fn visit_label ( & mut self , label : & ' ast Label ) {
185
195
walk_label ( self , label)
186
196
}
187
- fn visit_lifetime ( & mut self , lifetime : & ' ast Lifetime ) {
197
+ fn visit_lifetime ( & mut self , lifetime : & ' ast Lifetime , _ : LifetimeCtxt ) {
188
198
walk_lifetime ( self , lifetime)
189
199
}
190
200
fn visit_mac_call ( & mut self , mac : & ' ast MacCall ) {
@@ -414,7 +424,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
414
424
TyKind :: Slice ( ref ty) | TyKind :: Paren ( ref ty) => visitor. visit_ty ( ty) ,
415
425
TyKind :: Ptr ( ref mutable_type) => visitor. visit_ty ( & mutable_type. ty ) ,
416
426
TyKind :: Rptr ( ref opt_lifetime, ref mutable_type) => {
417
- walk_list ! ( visitor, visit_lifetime, opt_lifetime) ;
427
+ walk_list ! ( visitor, visit_lifetime, opt_lifetime, LifetimeCtxt :: Rptr ) ;
418
428
visitor. visit_ty ( & mutable_type. ty )
419
429
}
420
430
TyKind :: Tup ( ref tuple_element_types) => {
@@ -507,7 +517,7 @@ where
507
517
V : Visitor < ' a > ,
508
518
{
509
519
match generic_arg {
510
- GenericArg :: Lifetime ( lt) => visitor. visit_lifetime ( lt) ,
520
+ GenericArg :: Lifetime ( lt) => visitor. visit_lifetime ( lt, LifetimeCtxt :: GenericArg ) ,
511
521
GenericArg :: Type ( ty) => visitor. visit_ty ( ty) ,
512
522
GenericArg :: Const ( ct) => visitor. visit_anon_const ( ct) ,
513
523
}
@@ -599,7 +609,9 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
599
609
pub fn walk_param_bound < ' a , V : Visitor < ' a > > ( visitor : & mut V , bound : & ' a GenericBound ) {
600
610
match * bound {
601
611
GenericBound :: Trait ( ref typ, ref modifier) => visitor. visit_poly_trait_ref ( typ, modifier) ,
602
- GenericBound :: Outlives ( ref lifetime) => visitor. visit_lifetime ( lifetime) ,
612
+ GenericBound :: Outlives ( ref lifetime) => {
613
+ visitor. visit_lifetime ( lifetime, LifetimeCtxt :: Bound )
614
+ }
603
615
}
604
616
}
605
617
@@ -639,7 +651,7 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
639
651
WherePredicate :: RegionPredicate ( WhereRegionPredicate {
640
652
ref lifetime, ref bounds, ..
641
653
} ) => {
642
- visitor. visit_lifetime ( lifetime) ;
654
+ visitor. visit_lifetime ( lifetime, LifetimeCtxt :: Bound ) ;
643
655
walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
644
656
}
645
657
WherePredicate :: EqPredicate ( WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. } ) => {
0 commit comments