@@ -527,23 +527,20 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
527
527
} else {
528
528
0
529
529
} ;
530
- let mut type_count = 0 ;
531
- let lifetimes = generics
532
- . params
533
- . iter ( )
534
- . filter_map ( |param| match param. kind {
535
- GenericParamKind :: Lifetime { .. } => {
536
- Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
537
- }
538
- GenericParamKind :: Type { .. } => {
539
- type_count += 1 ;
540
- None
541
- }
542
- } )
543
- . collect ( ) ;
530
+ let mut non_lifetime_count = 0 ;
531
+ let lifetimes = generics. params . iter ( ) . filter_map ( |param| match param. kind {
532
+ GenericParamKind :: Lifetime { .. } => {
533
+ Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
534
+ }
535
+ GenericParamKind :: Type { .. } |
536
+ GenericParamKind :: Const { .. } => {
537
+ non_lifetime_count += 1 ;
538
+ None
539
+ }
540
+ } ) . collect ( ) ;
544
541
let scope = Scope :: Binder {
545
542
lifetimes,
546
- next_early_index : index + type_count ,
543
+ next_early_index : index + non_lifetime_count ,
547
544
abstract_type_parent : true ,
548
545
track_lifetime_uses,
549
546
s : ROOT_SCOPE ,
@@ -708,7 +705,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
708
705
709
706
let mut elision = None ;
710
707
let mut lifetimes = FxHashMap :: default ( ) ;
711
- let mut type_count = 0 ;
708
+ let mut non_lifetime_count = 0 ;
712
709
for param in & generics. params {
713
710
match param. kind {
714
711
GenericParamKind :: Lifetime { .. } => {
@@ -725,12 +722,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
725
722
lifetimes. insert ( name, reg) ;
726
723
}
727
724
}
728
- GenericParamKind :: Type { .. } => {
729
- type_count += 1 ;
725
+ GenericParamKind :: Type { .. } |
726
+ GenericParamKind :: Const { .. } => {
727
+ non_lifetime_count += 1 ;
730
728
}
731
729
}
732
730
}
733
- let next_early_index = index + type_count ;
731
+ let next_early_index = index + non_lifetime_count ;
734
732
735
733
if let Some ( elision_region) = elision {
736
734
let scope = Scope :: Elision {
@@ -788,23 +786,20 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
788
786
let generics = & trait_item. generics ;
789
787
let mut index = self . next_early_index ( ) ;
790
788
debug ! ( "visit_ty: index = {}" , index) ;
791
- let mut type_count = 0 ;
792
- let lifetimes = generics
793
- . params
794
- . iter ( )
795
- . filter_map ( |param| match param. kind {
796
- GenericParamKind :: Lifetime { .. } => {
797
- Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
798
- }
799
- GenericParamKind :: Type { .. } => {
800
- type_count += 1 ;
801
- None
802
- }
803
- } )
804
- . collect ( ) ;
789
+ let mut non_lifetime_count = 0 ;
790
+ let lifetimes = generics. params . iter ( ) . filter_map ( |param| match param. kind {
791
+ GenericParamKind :: Lifetime { .. } => {
792
+ Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
793
+ }
794
+ GenericParamKind :: Type { .. } |
795
+ GenericParamKind :: Const { .. } => {
796
+ non_lifetime_count += 1 ;
797
+ None
798
+ }
799
+ } ) . collect ( ) ;
805
800
let scope = Scope :: Binder {
806
801
lifetimes,
807
- next_early_index : index + type_count ,
802
+ next_early_index : index + non_lifetime_count ,
808
803
s : self . scope ,
809
804
track_lifetime_uses : true ,
810
805
abstract_type_parent : true ,
@@ -842,24 +837,21 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
842
837
Type ( ref ty) => {
843
838
let generics = & impl_item. generics ;
844
839
let mut index = self . next_early_index ( ) ;
845
- let mut next_early_index = index ;
840
+ let mut non_lifetime_count = 0 ;
846
841
debug ! ( "visit_ty: index = {}" , index) ;
847
- let lifetimes = generics
848
- . params
849
- . iter ( )
850
- . filter_map ( |param| match param. kind {
851
- GenericParamKind :: Lifetime { .. } => {
852
- Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
853
- }
854
- GenericParamKind :: Type { .. } => {
855
- next_early_index += 1 ;
856
- None
857
- }
858
- } )
859
- . collect ( ) ;
842
+ let lifetimes = generics. params . iter ( ) . filter_map ( |param| match param. kind {
843
+ GenericParamKind :: Lifetime { .. } => {
844
+ Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
845
+ }
846
+ GenericParamKind :: Const { .. } |
847
+ GenericParamKind :: Type { .. } => {
848
+ non_lifetime_count += 1 ;
849
+ None
850
+ }
851
+ } ) . collect ( ) ;
860
852
let scope = Scope :: Binder {
861
853
lifetimes,
862
- next_early_index,
854
+ next_early_index : index + non_lifetime_count ,
863
855
s : self . scope ,
864
856
track_lifetime_uses : true ,
865
857
abstract_type_parent : true ,
@@ -874,19 +866,19 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
874
866
let mut index = self . next_early_index ( ) ;
875
867
let mut next_early_index = index;
876
868
debug ! ( "visit_ty: index = {}" , index) ;
877
- let lifetimes = generics
878
- . params
879
- . iter ( )
880
- . filter_map ( |param| match param . kind {
881
- GenericParamKind :: Lifetime { .. } => {
882
- Some ( Region :: early ( & self . tcx . hir ( ) , & mut index , param ) )
883
- }
884
- GenericParamKind :: Type { .. } => {
885
- next_early_index += 1 ;
886
- None
887
- }
888
- } )
889
- . collect ( ) ;
869
+ let lifetimes = generics. params . iter ( ) . filter_map ( |param| match param . kind {
870
+ GenericParamKind :: Lifetime { .. } => {
871
+ Some ( Region :: early ( & self . tcx . hir ( ) , & mut index , param ) )
872
+ }
873
+ GenericParamKind :: Type { .. } => {
874
+ next_early_index += 1 ;
875
+ None
876
+ }
877
+ GenericParamKind :: Const { .. } => {
878
+ next_early_index += 1 ;
879
+ None
880
+ }
881
+ } ) . collect ( ) ;
890
882
891
883
let scope = Scope :: Binder {
892
884
lifetimes,
@@ -950,6 +942,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
950
942
self . visit_ty ( & ty) ;
951
943
}
952
944
}
945
+ GenericParamKind :: Const { ref ty, .. } => {
946
+ walk_list ! ( self , visit_param_bound, & param. bounds) ;
947
+ self . visit_ty ( & ty) ;
948
+ }
953
949
}
954
950
}
955
951
for predicate in & generics. where_clause . predicates {
@@ -1395,6 +1391,10 @@ fn object_lifetime_defaults_for_item(
1395
1391
Set1 :: Many => Set1 :: Many ,
1396
1392
} )
1397
1393
}
1394
+ GenericParamKind :: Const { .. } => {
1395
+ // Generic consts don't impose any constraints.
1396
+ None
1397
+ }
1398
1398
} )
1399
1399
. collect ( )
1400
1400
}
@@ -1703,25 +1703,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1703
1703
}
1704
1704
}
1705
1705
1706
- let mut type_count = 0 ;
1707
- let lifetimes = generics
1708
- . params
1709
- . iter ( )
1710
- . filter_map ( |param| match param. kind {
1711
- GenericParamKind :: Lifetime { .. } => {
1712
- if self . map . late_bound . contains ( & param. id ) {
1713
- Some ( Region :: late ( & self . tcx . hir ( ) , param) )
1714
- } else {
1715
- Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
1716
- }
1717
- }
1718
- GenericParamKind :: Type { .. } => {
1719
- type_count += 1 ;
1720
- None
1706
+ let mut non_lifetime_count = 0 ;
1707
+ let lifetimes = generics. params . iter ( ) . filter_map ( |param| match param. kind {
1708
+ GenericParamKind :: Lifetime { .. } => {
1709
+ if self . map . late_bound . contains ( & param. id ) {
1710
+ Some ( Region :: late ( & self . tcx . hir ( ) , param) )
1711
+ } else {
1712
+ Some ( Region :: early ( & self . tcx . hir ( ) , & mut index, param) )
1721
1713
}
1722
- } )
1723
- . collect ( ) ;
1724
- let next_early_index = index + type_count;
1714
+ }
1715
+ GenericParamKind :: Type { .. } |
1716
+ GenericParamKind :: Const { .. } => {
1717
+ non_lifetime_count += 1 ;
1718
+ None
1719
+ }
1720
+ } ) . collect ( ) ;
1721
+ let next_early_index = index + non_lifetime_count;
1725
1722
1726
1723
let scope = Scope :: Binder {
1727
1724
lifetimes,
@@ -2011,6 +2008,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
2011
2008
}
2012
2009
i += 1 ;
2013
2010
}
2011
+ GenericArg :: Const ( ct) => {
2012
+ self . visit_anon_const ( & ct. value ) ;
2013
+ }
2014
2014
}
2015
2015
}
2016
2016
@@ -2768,8 +2768,9 @@ fn insert_late_bound_lifetimes(
2768
2768
match param. kind {
2769
2769
hir:: GenericParamKind :: Lifetime { .. } => { /* fall through */ }
2770
2770
2771
- // Types are not late-bound.
2772
- hir:: GenericParamKind :: Type { .. } => continue ,
2771
+ // Neither types nor consts are late-bound.
2772
+ hir:: GenericParamKind :: Type { .. }
2773
+ | hir:: GenericParamKind :: Const { .. } => continue ,
2773
2774
}
2774
2775
2775
2776
let lt_name = hir:: LifetimeName :: Param ( param. name . modern ( ) ) ;
0 commit comments