@@ -646,30 +646,77 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
646
646
}
647
647
648
648
fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem ) {
649
- let tcx = self . tcx ;
650
- if let hir:: TraitItemKind :: Method ( ref sig, _) = trait_item. node {
651
- self . visit_early_late (
652
- Some ( tcx. hir . get_parent ( trait_item. id ) ) ,
653
- & sig. decl ,
654
- & trait_item. generics ,
655
- |this| intravisit:: walk_trait_item ( this, trait_item) ,
656
- )
657
- } else {
658
- intravisit:: walk_trait_item ( self , trait_item) ;
649
+ use self :: hir:: TraitItemKind :: * ;
650
+ match trait_item. node {
651
+ Method ( ref sig, _) => {
652
+ let tcx = self . tcx ;
653
+ self . visit_early_late (
654
+ Some ( tcx. hir . get_parent ( trait_item. id ) ) ,
655
+ & sig. decl ,
656
+ & trait_item. generics ,
657
+ |this| intravisit:: walk_trait_item ( this, trait_item) ,
658
+ ) ;
659
+ } ,
660
+ Type ( ref bounds, ref ty) => {
661
+ let generics = & trait_item. generics ;
662
+ let mut index = self . next_early_index ( ) ;
663
+ debug ! ( "visit_ty: index = {}" , index) ;
664
+ let lifetimes = generics. lifetimes . iter ( )
665
+ . map ( |lt_def| Region :: early ( & self . tcx . hir , & mut index, lt_def) )
666
+ . collect ( ) ;
667
+
668
+ let next_early_index = index + generics. ty_params . len ( ) as u32 ;
669
+ let scope = Scope :: Binder { lifetimes, next_early_index, s : self . scope } ;
670
+ self . with ( scope, |_old_scope, this| {
671
+ this. visit_generics ( generics) ;
672
+ for bound in bounds {
673
+ this. visit_ty_param_bound ( bound) ;
674
+ }
675
+ if let Some ( ty) = ty {
676
+ this. visit_ty ( ty) ;
677
+ }
678
+ } ) ;
679
+ } ,
680
+ Const ( _, _) => {
681
+ // Only methods and types support generics.
682
+ assert ! ( !trait_item. generics. is_parameterized( ) ) ;
683
+ intravisit:: walk_trait_item ( self , trait_item) ;
684
+ } ,
659
685
}
660
686
}
661
687
662
688
fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem ) {
663
- let tcx = self . tcx ;
664
- if let hir:: ImplItemKind :: Method ( ref sig, _) = impl_item. node {
665
- self . visit_early_late (
666
- Some ( tcx. hir . get_parent ( impl_item. id ) ) ,
667
- & sig. decl ,
668
- & impl_item. generics ,
669
- |this| intravisit:: walk_impl_item ( this, impl_item) ,
670
- )
671
- } else {
672
- intravisit:: walk_impl_item ( self , impl_item) ;
689
+ use self :: hir:: ImplItemKind :: * ;
690
+ match impl_item. node {
691
+ Method ( ref sig, _) => {
692
+ let tcx = self . tcx ;
693
+ self . visit_early_late (
694
+ Some ( tcx. hir . get_parent ( impl_item. id ) ) ,
695
+ & sig. decl ,
696
+ & impl_item. generics ,
697
+ |this| intravisit:: walk_impl_item ( this, impl_item) ,
698
+ )
699
+ } ,
700
+ Type ( ref ty) => {
701
+ let generics = & impl_item. generics ;
702
+ let mut index = self . next_early_index ( ) ;
703
+ debug ! ( "visit_ty: index = {}" , index) ;
704
+ let lifetimes = generics. lifetimes . iter ( )
705
+ . map ( |lt_def| Region :: early ( & self . tcx . hir , & mut index, lt_def) )
706
+ . collect ( ) ;
707
+
708
+ let next_early_index = index + generics. ty_params . len ( ) as u32 ;
709
+ let scope = Scope :: Binder { lifetimes, next_early_index, s : self . scope } ;
710
+ self . with ( scope, |_old_scope, this| {
711
+ this. visit_generics ( generics) ;
712
+ this. visit_ty ( ty) ;
713
+ } ) ;
714
+ } ,
715
+ Const ( _, _) => {
716
+ // Only methods and types support generics.
717
+ assert ! ( !impl_item. generics. is_parameterized( ) ) ;
718
+ intravisit:: walk_impl_item ( self , impl_item) ;
719
+ } ,
673
720
}
674
721
}
675
722
0 commit comments