@@ -89,6 +89,16 @@ impl<'a> FnKind<'a> {
8989 }
9090}
9191
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+
92102/// Each method of the `Visitor` trait is a hook to be potentially
93103/// overridden. Each method's default implementation recursively visits
94104/// the substructure of the input via the corresponding `walk` method;
@@ -184,7 +194,7 @@ pub trait Visitor<'ast>: Sized {
184194 fn visit_label ( & mut self , label : & ' ast Label ) {
185195 walk_label ( self , label)
186196 }
187- fn visit_lifetime ( & mut self , lifetime : & ' ast Lifetime ) {
197+ fn visit_lifetime ( & mut self , lifetime : & ' ast Lifetime , _ : LifetimeCtxt ) {
188198 walk_lifetime ( self , lifetime)
189199 }
190200 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) {
414424 TyKind :: Slice ( ref ty) | TyKind :: Paren ( ref ty) => visitor. visit_ty ( ty) ,
415425 TyKind :: Ptr ( ref mutable_type) => visitor. visit_ty ( & mutable_type. ty ) ,
416426 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 ) ;
418428 visitor. visit_ty ( & mutable_type. ty )
419429 }
420430 TyKind :: Tup ( ref tuple_element_types) => {
@@ -507,7 +517,7 @@ where
507517 V : Visitor < ' a > ,
508518{
509519 match generic_arg {
510- GenericArg :: Lifetime ( lt) => visitor. visit_lifetime ( lt) ,
520+ GenericArg :: Lifetime ( lt) => visitor. visit_lifetime ( lt, LifetimeCtxt :: GenericArg ) ,
511521 GenericArg :: Type ( ty) => visitor. visit_ty ( ty) ,
512522 GenericArg :: Const ( ct) => visitor. visit_anon_const ( ct) ,
513523 }
@@ -599,7 +609,9 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
599609pub fn walk_param_bound < ' a , V : Visitor < ' a > > ( visitor : & mut V , bound : & ' a GenericBound ) {
600610 match * bound {
601611 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+ }
603615 }
604616}
605617
@@ -639,7 +651,7 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
639651 WherePredicate :: RegionPredicate ( WhereRegionPredicate {
640652 ref lifetime, ref bounds, ..
641653 } ) => {
642- visitor. visit_lifetime ( lifetime) ;
654+ visitor. visit_lifetime ( lifetime, LifetimeCtxt :: Bound ) ;
643655 walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
644656 }
645657 WherePredicate :: EqPredicate ( WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. } ) => {
0 commit comments