@@ -957,34 +957,45 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
957
957
) -> SubstsRef < ' tcx > {
958
958
let generics = self . tcx . generics_of ( def_id) ;
959
959
let mut num_supplied_defaults = 0 ;
960
- let mut type_params = generics
961
- . params
962
- . iter ( )
963
- . rev ( )
964
- . filter_map ( |param| match param. kind {
965
- ty:: GenericParamDefKind :: Lifetime => None ,
966
- ty:: GenericParamDefKind :: Type { has_default, .. } => {
967
- Some ( ( param. def_id , has_default) )
968
- }
969
- // FIXME(const_generics:defaults)
970
- ty:: GenericParamDefKind :: Const { has_default : _has_default } => None ,
971
- } )
972
- . peekable ( ) ;
973
- let has_default = {
974
- let has_default = type_params. peek ( ) . map ( |( _, has_default) | has_default) ;
975
- * has_default. unwrap_or ( & false )
976
- } ;
977
- if has_default {
978
- let types = substs. types ( ) . rev ( ) ;
979
- for ( ( def_id, has_default) , actual) in type_params. zip ( types) {
980
- if !has_default {
981
- break ;
960
+
961
+ #[ derive( PartialEq , Eq , Copy , Clone ) ]
962
+ enum Kind {
963
+ Const ,
964
+ Type ,
965
+ }
966
+ let default_params = generics. params . iter ( ) . rev ( ) . filter_map ( |param| match param. kind {
967
+ ty:: GenericParamDefKind :: Type { has_default : true , .. } => {
968
+ Some ( ( param. def_id , Kind :: Type ) )
969
+ }
970
+ ty:: GenericParamDefKind :: Const { has_default : true } => {
971
+ Some ( ( param. def_id , Kind :: Const ) )
972
+ }
973
+ _ => None ,
974
+ } ) ;
975
+ let mut types = substs. types ( ) . rev ( ) ;
976
+ let mut consts = substs. consts ( ) . rev ( ) ;
977
+ for ( def_id, kind) in default_params {
978
+ match kind {
979
+ Kind :: Const => {
980
+ if let Some ( actual) = consts. next ( ) {
981
+ if ty:: Const :: from_anon_const ( self . tcx , def_id. expect_local ( ) ) != actual {
982
+ break ;
983
+ }
984
+ } else {
985
+ break ;
986
+ }
982
987
}
983
- if self . tcx . type_of ( def_id) . subst ( self . tcx , substs) != actual {
984
- break ;
988
+ Kind :: Type => {
989
+ if let Some ( actual) = types. next ( ) {
990
+ if self . tcx . type_of ( def_id) . subst ( self . tcx , substs) != actual {
991
+ break ;
992
+ }
993
+ } else {
994
+ break ;
995
+ }
985
996
}
986
- num_supplied_defaults += 1 ;
987
997
}
998
+ num_supplied_defaults += 1 ;
988
999
}
989
1000
let len = generics. params . len ( ) ;
990
1001
let mut generics = generics. clone ( ) ;
0 commit comments