@@ -33,9 +33,21 @@ pub enum FnCtxt {
33
33
}
34
34
35
35
#[ 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`.
38
47
TraitObject ,
48
+
49
+ /// Super traits of a trait.
50
+ /// E.g., `trait A: B`
39
51
SuperTraits ,
40
52
}
41
53
@@ -146,7 +158,7 @@ pub trait Visitor<'ast>: Sized {
146
158
fn visit_trait_ref ( & mut self , t : & ' ast TraitRef ) {
147
159
walk_trait_ref ( self , t)
148
160
}
149
- fn visit_param_bound ( & mut self , bounds : & ' ast GenericBound , _ctxt : BoundCtxt ) {
161
+ fn visit_param_bound ( & mut self , bounds : & ' ast GenericBound , _ctxt : BoundKind ) {
150
162
walk_param_bound ( self , bounds)
151
163
}
152
164
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) {
318
330
ItemKind :: GlobalAsm ( ref asm) => walk_inline_asm ( visitor, asm) ,
319
331
ItemKind :: TyAlias ( box TyAlias { ref generics, ref bounds, ref ty, .. } ) => {
320
332
visitor. visit_generics ( generics) ;
321
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
333
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
322
334
walk_list ! ( visitor, visit_ty, ty) ;
323
335
}
324
336
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) {
353
365
ref items,
354
366
} ) => {
355
367
visitor. visit_generics ( generics) ;
356
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: SuperTraits ) ;
368
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: SuperTraits ) ;
357
369
walk_list ! ( visitor, visit_assoc_item, items, AssocCtxt :: Trait ) ;
358
370
}
359
371
ItemKind :: TraitAlias ( ref generics, ref bounds) => {
360
372
visitor. visit_generics ( generics) ;
361
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
373
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
362
374
}
363
375
ItemKind :: MacCall ( ref mac) => visitor. visit_mac_call ( mac) ,
364
376
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) {
424
436
visitor. visit_anon_const ( length)
425
437
}
426
438
TyKind :: TraitObject ( ref bounds, ..) => {
427
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: TraitObject ) ;
439
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: TraitObject ) ;
428
440
}
429
441
TyKind :: ImplTrait ( _, ref bounds) => {
430
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
442
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Impl ) ;
431
443
}
432
444
TyKind :: Typeof ( ref expression) => visitor. visit_anon_const ( expression) ,
433
445
TyKind :: Infer | TyKind :: ImplicitSelf | TyKind :: Err => { }
@@ -513,7 +525,7 @@ pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'
513
525
Term :: Const ( c) => visitor. visit_anon_const ( c) ,
514
526
} ,
515
527
AssocConstraintKind :: Bound { ref bounds } => {
516
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
528
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
517
529
}
518
530
}
519
531
}
@@ -576,7 +588,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
576
588
}
577
589
ForeignItemKind :: TyAlias ( box TyAlias { generics, bounds, ty, .. } ) => {
578
590
visitor. visit_generics ( generics) ;
579
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
591
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
580
592
walk_list ! ( visitor, visit_ty, ty) ;
581
593
}
582
594
ForeignItemKind :: MacCall ( mac) => {
@@ -595,7 +607,7 @@ pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericB
595
607
pub fn walk_generic_param < ' a , V : Visitor < ' a > > ( visitor : & mut V , param : & ' a GenericParam ) {
596
608
visitor. visit_ident ( param. ident ) ;
597
609
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 ) ;
599
611
match param. kind {
600
612
GenericParamKind :: Lifetime => ( ) ,
601
613
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
622
634
..
623
635
} ) => {
624
636
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 ) ;
626
638
walk_list ! ( visitor, visit_generic_param, bound_generic_params) ;
627
639
}
628
640
WherePredicate :: RegionPredicate ( WhereRegionPredicate {
629
641
ref lifetime, ref bounds, ..
630
642
} ) => {
631
643
visitor. visit_lifetime ( lifetime) ;
632
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
644
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
633
645
}
634
646
WherePredicate :: EqPredicate ( WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. } ) => {
635
647
visitor. visit_ty ( lhs_ty) ;
@@ -682,7 +694,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
682
694
}
683
695
AssocItemKind :: TyAlias ( box TyAlias { generics, bounds, ty, .. } ) => {
684
696
visitor. visit_generics ( generics) ;
685
- walk_list ! ( visitor, visit_param_bound, bounds, BoundCtxt :: Normal ) ;
697
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
686
698
walk_list ! ( visitor, visit_ty, ty) ;
687
699
}
688
700
AssocItemKind :: MacCall ( mac) => {
0 commit comments