@@ -527,23 +527,20 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
527527 } else {
528528 0
529529 } ;
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 ( ) ;
544541 let scope = Scope :: Binder {
545542 lifetimes,
546- next_early_index : index + type_count ,
543+ next_early_index : index + non_lifetime_count ,
547544 abstract_type_parent : true ,
548545 track_lifetime_uses,
549546 s : ROOT_SCOPE ,
@@ -708,7 +705,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
708705
709706 let mut elision = None ;
710707 let mut lifetimes = FxHashMap :: default ( ) ;
711- let mut type_count = 0 ;
708+ let mut non_lifetime_count = 0 ;
712709 for param in & generics. params {
713710 match param. kind {
714711 GenericParamKind :: Lifetime { .. } => {
@@ -725,12 +722,13 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
725722 lifetimes. insert ( name, reg) ;
726723 }
727724 }
728- GenericParamKind :: Type { .. } => {
729- type_count += 1 ;
725+ GenericParamKind :: Type { .. } |
726+ GenericParamKind :: Const { .. } => {
727+ non_lifetime_count += 1 ;
730728 }
731729 }
732730 }
733- let next_early_index = index + type_count ;
731+ let next_early_index = index + non_lifetime_count ;
734732
735733 if let Some ( elision_region) = elision {
736734 let scope = Scope :: Elision {
@@ -788,23 +786,20 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
788786 let generics = & trait_item. generics ;
789787 let mut index = self . next_early_index ( ) ;
790788 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 ( ) ;
805800 let scope = Scope :: Binder {
806801 lifetimes,
807- next_early_index : index + type_count ,
802+ next_early_index : index + non_lifetime_count ,
808803 s : self . scope ,
809804 track_lifetime_uses : true ,
810805 abstract_type_parent : true ,
@@ -842,24 +837,21 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
842837 Type ( ref ty) => {
843838 let generics = & impl_item. generics ;
844839 let mut index = self . next_early_index ( ) ;
845- let mut next_early_index = index ;
840+ let mut non_lifetime_count = 0 ;
846841 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 ( ) ;
860852 let scope = Scope :: Binder {
861853 lifetimes,
862- next_early_index,
854+ next_early_index : index + non_lifetime_count ,
863855 s : self . scope ,
864856 track_lifetime_uses : true ,
865857 abstract_type_parent : true ,
@@ -874,19 +866,19 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
874866 let mut index = self . next_early_index ( ) ;
875867 let mut next_early_index = index;
876868 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 ( ) ;
890882
891883 let scope = Scope :: Binder {
892884 lifetimes,
@@ -950,6 +942,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
950942 self . visit_ty ( & ty) ;
951943 }
952944 }
945+ GenericParamKind :: Const { ref ty, .. } => {
946+ walk_list ! ( self , visit_param_bound, & param. bounds) ;
947+ self . visit_ty ( & ty) ;
948+ }
953949 }
954950 }
955951 for predicate in & generics. where_clause . predicates {
@@ -1395,6 +1391,10 @@ fn object_lifetime_defaults_for_item(
13951391 Set1 :: Many => Set1 :: Many ,
13961392 } )
13971393 }
1394+ GenericParamKind :: Const { .. } => {
1395+ // Generic consts don't impose any constraints.
1396+ None
1397+ }
13981398 } )
13991399 . collect ( )
14001400}
@@ -1703,25 +1703,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17031703 }
17041704 }
17051705
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) )
17211713 }
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;
17251722
17261723 let scope = Scope :: Binder {
17271724 lifetimes,
@@ -2011,6 +2008,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
20112008 }
20122009 i += 1 ;
20132010 }
2011+ GenericArg :: Const ( ct) => {
2012+ self . visit_anon_const ( & ct. value ) ;
2013+ }
20142014 }
20152015 }
20162016
@@ -2768,8 +2768,9 @@ fn insert_late_bound_lifetimes(
27682768 match param. kind {
27692769 hir:: GenericParamKind :: Lifetime { .. } => { /* fall through */ }
27702770
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 ,
27732774 }
27742775
27752776 let lt_name = hir:: LifetimeName :: Param ( param. name . modern ( ) ) ;
0 commit comments