@@ -32,6 +32,25 @@ pub enum FnCtxt {
32
32
Assoc ( AssocCtxt ) ,
33
33
}
34
34
35
+ #[ derive( Copy , Clone , Debug ) ]
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`.
47
+ TraitObject ,
48
+
49
+ /// Super traits of a trait.
50
+ /// E.g., `trait A: B`
51
+ SuperTraits ,
52
+ }
53
+
35
54
#[ derive( Copy , Clone , Debug ) ]
36
55
pub enum FnKind < ' a > {
37
56
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
@@ -139,7 +158,7 @@ pub trait Visitor<'ast>: Sized {
139
158
fn visit_trait_ref ( & mut self , t : & ' ast TraitRef ) {
140
159
walk_trait_ref ( self , t)
141
160
}
142
- fn visit_param_bound ( & mut self , bounds : & ' ast GenericBound ) {
161
+ fn visit_param_bound ( & mut self , bounds : & ' ast GenericBound , _ctxt : BoundKind ) {
143
162
walk_param_bound ( self , bounds)
144
163
}
145
164
fn visit_poly_trait_ref ( & mut self , t : & ' ast PolyTraitRef , m : & ' ast TraitBoundModifier ) {
@@ -311,7 +330,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
311
330
ItemKind :: GlobalAsm ( ref asm) => walk_inline_asm ( visitor, asm) ,
312
331
ItemKind :: TyAlias ( box TyAlias { ref generics, ref bounds, ref ty, .. } ) => {
313
332
visitor. visit_generics ( generics) ;
314
- walk_list ! ( visitor, visit_param_bound, bounds) ;
333
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
315
334
walk_list ! ( visitor, visit_ty, ty) ;
316
335
}
317
336
ItemKind :: Enum ( ref enum_definition, ref generics) => {
@@ -346,12 +365,12 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
346
365
ref items,
347
366
} ) => {
348
367
visitor. visit_generics ( generics) ;
349
- walk_list ! ( visitor, visit_param_bound, bounds) ;
368
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: SuperTraits ) ;
350
369
walk_list ! ( visitor, visit_assoc_item, items, AssocCtxt :: Trait ) ;
351
370
}
352
371
ItemKind :: TraitAlias ( ref generics, ref bounds) => {
353
372
visitor. visit_generics ( generics) ;
354
- walk_list ! ( visitor, visit_param_bound, bounds) ;
373
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
355
374
}
356
375
ItemKind :: MacCall ( ref mac) => visitor. visit_mac_call ( mac) ,
357
376
ItemKind :: MacroDef ( ref ts) => visitor. visit_mac_def ( ts, item. id ) ,
@@ -416,8 +435,11 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
416
435
visitor. visit_ty ( ty) ;
417
436
visitor. visit_anon_const ( length)
418
437
}
419
- TyKind :: TraitObject ( ref bounds, ..) | TyKind :: ImplTrait ( _, ref bounds) => {
420
- walk_list ! ( visitor, visit_param_bound, bounds) ;
438
+ TyKind :: TraitObject ( ref bounds, ..) => {
439
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: TraitObject ) ;
440
+ }
441
+ TyKind :: ImplTrait ( _, ref bounds) => {
442
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Impl ) ;
421
443
}
422
444
TyKind :: Typeof ( ref expression) => visitor. visit_anon_const ( expression) ,
423
445
TyKind :: Infer | TyKind :: ImplicitSelf | TyKind :: Err => { }
@@ -503,7 +525,7 @@ pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'
503
525
Term :: Const ( c) => visitor. visit_anon_const ( c) ,
504
526
} ,
505
527
AssocConstraintKind :: Bound { ref bounds } => {
506
- walk_list ! ( visitor, visit_param_bound, bounds) ;
528
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
507
529
}
508
530
}
509
531
}
@@ -566,7 +588,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
566
588
}
567
589
ForeignItemKind :: TyAlias ( box TyAlias { generics, bounds, ty, .. } ) => {
568
590
visitor. visit_generics ( generics) ;
569
- walk_list ! ( visitor, visit_param_bound, bounds) ;
591
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
570
592
walk_list ! ( visitor, visit_ty, ty) ;
571
593
}
572
594
ForeignItemKind :: MacCall ( mac) => {
@@ -585,7 +607,7 @@ pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericB
585
607
pub fn walk_generic_param < ' a , V : Visitor < ' a > > ( visitor : & mut V , param : & ' a GenericParam ) {
586
608
visitor. visit_ident ( param. ident ) ;
587
609
walk_list ! ( visitor, visit_attribute, param. attrs. iter( ) ) ;
588
- walk_list ! ( visitor, visit_param_bound, & param. bounds) ;
610
+ walk_list ! ( visitor, visit_param_bound, & param. bounds, BoundKind :: Bound ) ;
589
611
match param. kind {
590
612
GenericParamKind :: Lifetime => ( ) ,
591
613
GenericParamKind :: Type { ref default } => walk_list ! ( visitor, visit_ty, default ) ,
@@ -612,14 +634,14 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
612
634
..
613
635
} ) => {
614
636
visitor. visit_ty ( bounded_ty) ;
615
- walk_list ! ( visitor, visit_param_bound, bounds) ;
637
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
616
638
walk_list ! ( visitor, visit_generic_param, bound_generic_params) ;
617
639
}
618
640
WherePredicate :: RegionPredicate ( WhereRegionPredicate {
619
641
ref lifetime, ref bounds, ..
620
642
} ) => {
621
643
visitor. visit_lifetime ( lifetime) ;
622
- walk_list ! ( visitor, visit_param_bound, bounds) ;
644
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
623
645
}
624
646
WherePredicate :: EqPredicate ( WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. } ) => {
625
647
visitor. visit_ty ( lhs_ty) ;
@@ -672,7 +694,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
672
694
}
673
695
AssocItemKind :: TyAlias ( box TyAlias { generics, bounds, ty, .. } ) => {
674
696
visitor. visit_generics ( generics) ;
675
- walk_list ! ( visitor, visit_param_bound, bounds) ;
697
+ walk_list ! ( visitor, visit_param_bound, bounds, BoundKind :: Bound ) ;
676
698
walk_list ! ( visitor, visit_ty, ty) ;
677
699
}
678
700
AssocItemKind :: MacCall ( mac) => {
0 commit comments