@@ -837,7 +837,8 @@ pub enum GenericParamDefKind {
837
837
has_default : bool ,
838
838
object_lifetime_default : ObjectLifetimeDefault ,
839
839
synthetic : Option < hir:: SyntheticTyParamKind > ,
840
- }
840
+ } ,
841
+ Const ,
841
842
}
842
843
843
844
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
@@ -880,6 +881,7 @@ impl GenericParamDef {
880
881
pub struct GenericParamCount {
881
882
pub lifetimes : usize ,
882
883
pub types : usize ,
884
+ pub consts : usize ,
883
885
}
884
886
885
887
/// Information about the formal type/lifetime parameters associated
@@ -915,6 +917,7 @@ impl<'a, 'gcx, 'tcx> Generics {
915
917
match param. kind {
916
918
GenericParamDefKind :: Lifetime => own_counts. lifetimes += 1 ,
917
919
GenericParamDefKind :: Type { .. } => own_counts. types += 1 ,
920
+ GenericParamDefKind :: Const => own_counts. consts += 1 ,
918
921
} ;
919
922
}
920
923
@@ -924,7 +927,7 @@ impl<'a, 'gcx, 'tcx> Generics {
924
927
pub fn requires_monomorphization ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> bool {
925
928
for param in & self . params {
926
929
match param. kind {
927
- GenericParamDefKind :: Type { .. } => return true ,
930
+ GenericParamDefKind :: Type { .. } | GenericParamDefKind :: Const => return true ,
928
931
GenericParamDefKind :: Lifetime => { }
929
932
}
930
933
}
@@ -944,7 +947,7 @@ impl<'a, 'gcx, 'tcx> Generics {
944
947
if let Some ( index) = param. index . checked_sub ( self . parent_count as u32 ) {
945
948
let param = & self . params [ index as usize ] ;
946
949
match param. kind {
947
- ty :: GenericParamDefKind :: Lifetime => param,
950
+ GenericParamDefKind :: Lifetime => param,
948
951
_ => bug ! ( "expected lifetime parameter, but found another generic parameter" )
949
952
}
950
953
} else {
@@ -961,14 +964,31 @@ impl<'a, 'gcx, 'tcx> Generics {
961
964
if let Some ( index) = param. idx . checked_sub ( self . parent_count as u32 ) {
962
965
let param = & self . params [ index as usize ] ;
963
966
match param. kind {
964
- ty :: GenericParamDefKind :: Type { .. } => param,
967
+ GenericParamDefKind :: Type { .. } => param,
965
968
_ => bug ! ( "expected type parameter, but found another generic parameter" )
966
969
}
967
970
} else {
968
971
tcx. generics_of ( self . parent . expect ( "parent_count > 0 but no parent?" ) )
969
972
. type_param ( param, tcx)
970
973
}
971
974
}
975
+
976
+ /// Returns the `ConstParameterDef` associated with this `ParamConst`.
977
+ pub fn const_param ( & ' tcx self ,
978
+ param : & ParamConst ,
979
+ tcx : TyCtxt < ' a , ' gcx , ' tcx > )
980
+ -> & GenericParamDef {
981
+ if let Some ( index) = param. index . checked_sub ( self . parent_count as u32 ) {
982
+ let param = & self . params [ index as usize ] ;
983
+ match param. kind {
984
+ GenericParamDefKind :: Const => param,
985
+ _ => bug ! ( "expected const parameter, but found another generic parameter" )
986
+ }
987
+ } else {
988
+ tcx. generics_of ( self . parent . expect ( "parent_count>0 but no parent?" ) )
989
+ . const_param ( param, tcx)
990
+ }
991
+ }
972
992
}
973
993
974
994
/// Bounds on generics.
0 commit comments