@@ -772,6 +772,92 @@ fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
772
772
tcx. alloc_trait_def ( def)
773
773
}
774
774
775
+ fn has_late_bound_regions < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
776
+ node : hir_map:: Node < ' tcx > )
777
+ -> bool {
778
+ struct LateBoundRegionsDetector < ' a , ' tcx : ' a > {
779
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
780
+ binder_depth : usize ,
781
+ has_late_bound_regions : bool ,
782
+ }
783
+
784
+ impl < ' a , ' tcx > Visitor < ' tcx > for LateBoundRegionsDetector < ' a , ' tcx > {
785
+ fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
786
+ NestedVisitorMap :: None
787
+ }
788
+
789
+ fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty ) {
790
+ if self . has_late_bound_regions { return }
791
+ match ty. node {
792
+ hir:: TyBareFn ( ..) => {
793
+ self . binder_depth += 1 ;
794
+ intravisit:: walk_ty ( self , ty) ;
795
+ self . binder_depth -= 1 ;
796
+ }
797
+ _ => intravisit:: walk_ty ( self , ty)
798
+ }
799
+ }
800
+
801
+ fn visit_poly_trait_ref ( & mut self ,
802
+ tr : & ' tcx hir:: PolyTraitRef ,
803
+ m : hir:: TraitBoundModifier ) {
804
+ if self . has_late_bound_regions { return }
805
+ self . binder_depth += 1 ;
806
+ intravisit:: walk_poly_trait_ref ( self , tr, m) ;
807
+ self . binder_depth -= 1 ;
808
+ }
809
+
810
+ fn visit_lifetime ( & mut self , lt : & ' tcx hir:: Lifetime ) {
811
+ if self . has_late_bound_regions { return }
812
+
813
+ match self . tcx . named_region_map . defs . get ( & lt. id ) . cloned ( ) {
814
+ Some ( rl:: Region :: Static ) | Some ( rl:: Region :: EarlyBound ( ..) ) => { }
815
+ _ => self . has_late_bound_regions = true
816
+ }
817
+ }
818
+ }
819
+
820
+ fn has_late_bound_regions < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
821
+ generics : & ' tcx hir:: Generics ,
822
+ decl : & ' tcx hir:: FnDecl )
823
+ -> bool {
824
+ let mut visitor = LateBoundRegionsDetector {
825
+ tcx, binder_depth : 0 , has_late_bound_regions : false
826
+ } ;
827
+ for lifetime in & generics. lifetimes {
828
+ if tcx. named_region_map . late_bound . contains ( & lifetime. lifetime . id ) {
829
+ return true ;
830
+ }
831
+ }
832
+ visitor. visit_fn_decl ( decl) ;
833
+ visitor. has_late_bound_regions
834
+ }
835
+
836
+ match node {
837
+ hir_map:: NodeTraitItem ( item) => match item. node {
838
+ hir:: TraitItemKind :: Method ( ref sig, _) =>
839
+ has_late_bound_regions ( tcx, & sig. generics , & sig. decl ) ,
840
+ _ => false ,
841
+ } ,
842
+ hir_map:: NodeImplItem ( item) => match item. node {
843
+ hir:: ImplItemKind :: Method ( ref sig, _) =>
844
+ has_late_bound_regions ( tcx, & sig. generics , & sig. decl ) ,
845
+ _ => false ,
846
+ } ,
847
+ hir_map:: NodeForeignItem ( item) => match item. node {
848
+ hir:: ForeignItemFn ( ref fn_decl, _, ref generics) =>
849
+ has_late_bound_regions ( tcx, generics, fn_decl) ,
850
+ _ => false ,
851
+ } ,
852
+ hir_map:: NodeItem ( item) => match item. node {
853
+ hir:: ItemFn ( ref fn_decl, .., ref generics, _) =>
854
+ has_late_bound_regions ( tcx, generics, fn_decl) ,
855
+ _ => false ,
856
+ } ,
857
+ _ => false
858
+ }
859
+ }
860
+
775
861
fn generics_of < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
776
862
def_id : DefId )
777
863
-> & ' tcx ty:: Generics {
@@ -876,13 +962,11 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
876
962
877
963
let has_self = opt_self. is_some ( ) ;
878
964
let mut parent_has_self = false ;
879
- let mut parent_has_late_bound_regions = false ;
880
965
let mut own_start = has_self as u32 ;
881
966
let ( parent_regions, parent_types) = parent_def_id. map_or ( ( 0 , 0 ) , |def_id| {
882
967
let generics = tcx. generics_of ( def_id) ;
883
968
assert_eq ! ( has_self, false ) ;
884
969
parent_has_self = generics. has_self ;
885
- parent_has_late_bound_regions = generics. has_late_bound_regions ;
886
970
own_start = generics. count ( ) as u32 ;
887
971
( generics. parent_regions + generics. regions . len ( ) as u32 ,
888
972
generics. parent_types + generics. types . len ( ) as u32 )
@@ -900,7 +984,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
900
984
}
901
985
} ) . collect :: < Vec < _ > > ( ) ;
902
986
903
- let has_late_bound_regions = regions. len ( ) != ast_generics. lifetimes . len ( ) ;
904
987
let object_lifetime_defaults =
905
988
tcx. named_region_map . object_lifetime_defaults . get ( & node_id) ;
906
989
@@ -963,7 +1046,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
963
1046
types : types,
964
1047
type_param_to_index : type_param_to_index,
965
1048
has_self : has_self || parent_has_self,
966
- has_late_bound_regions : has_late_bound_regions || parent_has_late_bound_regions ,
1049
+ has_late_bound_regions : has_late_bound_regions ( tcx , node ) ,
967
1050
} )
968
1051
}
969
1052
0 commit comments