@@ -33,9 +33,21 @@ pub enum FnCtxt {
3333}
3434
3535#[ derive( Copy , Clone , Debug ) ]
36- pub enum BoundCtxt {
37- Normal ,
36+ pub enum BoundKind {
37+ /// Trait bounds in generics bounds and type/trait alias.
38+ /// E.g., `<T: Bound>`, `type A: Bound`, or `where T: Bound`.
39+ Bound ,
40+
41+ /// Trait bounds in `impl` type.
42+ /// E.g., `type Foo = impl Bound1 + Bound2 + Bound3`.
43+ Impl ,
44+
45+ /// Trait bounds in trait object type.
46+ /// E.g., `dyn Bound1 + Bound2 + Bound3`.
3847 TraitObject ,
48+
49+ /// Super traits of a trait.
50+ /// E.g., `trait A: B`
3951 SuperTraits ,
4052}
4153
@@ -146,7 +158,7 @@ pub trait Visitor<'ast>: Sized {
146158 fn visit_trait_ref ( & mut self , t : & ' ast TraitRef ) {
147159 walk_trait_ref ( self , t)
148160 }
149- fn visit_param_bound ( & mut self , bounds : & ' ast GenericBound , _ctxt : BoundCtxt ) {
161+ fn visit_param_bound ( & mut self , bounds : & ' ast GenericBound , _ctxt : BoundKind ) {
150162 walk_param_bound ( self , bounds)
151163 }
152164 fn visit_poly_trait_ref ( & mut self , t : & ' ast PolyTraitRef , m : & ' ast TraitBoundModifier ) {
@@ -318,7 +330,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
318330 ItemKind :: GlobalAsm ( ref asm) => walk_inline_asm ( visitor, asm) ,
319331 ItemKind :: TyAlias ( box TyAlias { ref generics, ref bounds, ref ty, .. } ) => {
320332 visitor. visit_generics ( generics) ;
321- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
333+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
322334 walk_list ! ( visitor, visit_ty, ty) ;
323335 }
324336 ItemKind :: Enum ( ref enum_definition, ref generics) => {
@@ -353,12 +365,12 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
353365 ref items,
354366 } ) => {
355367 visitor. visit_generics ( generics) ;
356- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: SuperTraits ) ;
368+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: SuperTraits ) ;
357369 walk_list ! ( visitor, visit_assoc_item, items, AssocCtxt :: Trait ) ;
358370 }
359371 ItemKind :: TraitAlias ( ref generics, ref bounds) => {
360372 visitor. visit_generics ( generics) ;
361- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
373+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
362374 }
363375 ItemKind :: MacCall ( ref mac) => visitor. visit_mac_call ( mac) ,
364376 ItemKind :: MacroDef ( ref ts) => visitor. visit_mac_def ( ts, item. id ) ,
@@ -424,10 +436,10 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
424436 visitor. visit_anon_const ( length)
425437 }
426438 TyKind :: TraitObject ( ref bounds, ..) => {
427- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: TraitObject ) ;
439+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: TraitObject ) ;
428440 }
429441 TyKind :: ImplTrait ( _, ref bounds) => {
430- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
442+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Impl ) ;
431443 }
432444 TyKind :: Typeof ( ref expression) => visitor. visit_anon_const ( expression) ,
433445 TyKind :: Infer | TyKind :: ImplicitSelf | TyKind :: Err => { }
@@ -513,7 +525,7 @@ pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'
513525 Term :: Const ( c) => visitor. visit_anon_const ( c) ,
514526 } ,
515527 AssocConstraintKind :: Bound { ref bounds } => {
516- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
528+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
517529 }
518530 }
519531}
@@ -576,7 +588,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
576588 }
577589 ForeignItemKind :: TyAlias ( box TyAlias { generics, bounds, ty, .. } ) => {
578590 visitor. visit_generics ( generics) ;
579- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
591+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
580592 walk_list ! ( visitor, visit_ty, ty) ;
581593 }
582594 ForeignItemKind :: MacCall ( mac) => {
@@ -595,7 +607,7 @@ pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericB
595607pub fn walk_generic_param < ' a , V : Visitor < ' a > > ( visitor : & mut V , param : & ' a GenericParam ) {
596608 visitor. visit_ident ( param. ident ) ;
597609 walk_list ! ( visitor, visit_attribute, param. attrs. iter( ) ) ;
598- walk_list ! ( visitor, visit_param_bound, & param. bounds, BoundCtxt :: Normal ) ;
610+ walk_list ! ( visitor, visit_param_bound, & param. bounds, BoundKind :: Bound ) ;
599611 match param. kind {
600612 GenericParamKind :: Lifetime => ( ) ,
601613 GenericParamKind :: Type { ref default } => walk_list ! ( visitor, visit_ty, default ) ,
@@ -622,14 +634,14 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
622634 ..
623635 } ) => {
624636 visitor. visit_ty ( bounded_ty) ;
625- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
637+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
626638 walk_list ! ( visitor, visit_generic_param, bound_generic_params) ;
627639 }
628640 WherePredicate :: RegionPredicate ( WhereRegionPredicate {
629641 ref lifetime, ref bounds, ..
630642 } ) => {
631643 visitor. visit_lifetime ( lifetime) ;
632- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
644+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
633645 }
634646 WherePredicate :: EqPredicate ( WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. } ) => {
635647 visitor. visit_ty ( lhs_ty) ;
@@ -682,7 +694,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
682694 }
683695 AssocItemKind :: TyAlias ( box TyAlias { generics, bounds, ty, .. } ) => {
684696 visitor. visit_generics ( generics) ;
685- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
697+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
686698 walk_list ! ( visitor, visit_ty, ty) ;
687699 }
688700 AssocItemKind :: MacCall ( mac) => {
0 commit comments