@@ -2570,18 +2570,30 @@ impl<'tcx> TyCtxt<'tcx> {
2570
2570
def_id : DefId ,
2571
2571
substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
2572
2572
) -> Ty < ' tcx > {
2573
- let substs = substs. into_iter ( ) . map ( Into :: into) ;
2574
- let n = self . generics_of ( def_id) . count ( ) ;
2575
- debug_assert_eq ! (
2576
- ( n, Some ( n) ) ,
2577
- substs. size_hint( ) ,
2578
- "wrong number of generic parameters for {def_id:?}: {:?} \n Did you accidentally include the self-type in the params list?" ,
2579
- substs. collect:: <Vec <_>>( ) ,
2580
- ) ;
2581
- let substs = self . mk_substs ( substs) ;
2573
+ let substs = self . check_substs ( def_id, substs) ;
2582
2574
self . mk_ty ( FnDef ( def_id, substs) )
2583
2575
}
2584
2576
2577
+ #[ inline( always) ]
2578
+ fn check_substs (
2579
+ self ,
2580
+ def_id : DefId ,
2581
+ substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
2582
+ ) -> SubstsRef < ' tcx > {
2583
+ let substs = substs. into_iter ( ) . map ( Into :: into) ;
2584
+ #[ cfg( debug_assertions) ]
2585
+ {
2586
+ let n = self . generics_of ( def_id) . count ( ) ;
2587
+ assert_eq ! (
2588
+ ( n, Some ( n) ) ,
2589
+ substs. size_hint( ) ,
2590
+ "wrong number of generic parameters for {def_id:?}: {:?}" ,
2591
+ substs. collect:: <Vec <_>>( ) ,
2592
+ ) ;
2593
+ }
2594
+ self . mk_substs ( substs)
2595
+ }
2596
+
2585
2597
#[ inline]
2586
2598
pub fn mk_fn_ptr ( self , fty : PolyFnSig < ' tcx > ) -> Ty < ' tcx > {
2587
2599
self . mk_ty ( FnPtr ( fty) )
@@ -2862,15 +2874,7 @@ impl<'tcx> TyCtxt<'tcx> {
2862
2874
trait_def_id : DefId ,
2863
2875
substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
2864
2876
) -> ty:: TraitRef < ' tcx > {
2865
- let substs = substs. into_iter ( ) . map ( Into :: into) ;
2866
- let n = self . generics_of ( trait_def_id) . count ( ) ;
2867
- debug_assert_eq ! (
2868
- ( n, Some ( n) ) ,
2869
- substs. size_hint( ) ,
2870
- "wrong number of generic parameters for {trait_def_id:?}: {:?} \n Did you accidentally include the self-type in the params list?" ,
2871
- substs. collect:: <Vec <_>>( ) ,
2872
- ) ;
2873
- let substs = self . mk_substs ( substs) ;
2877
+ let substs = self . check_substs ( trait_def_id, substs) ;
2874
2878
ty:: TraitRef { def_id : trait_def_id, substs, _use_mk_trait_ref_instead : ( ) }
2875
2879
}
2876
2880
@@ -2879,15 +2883,7 @@ impl<'tcx> TyCtxt<'tcx> {
2879
2883
def_id : DefId ,
2880
2884
substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
2881
2885
) -> ty:: AliasTy < ' tcx > {
2882
- let substs = substs. into_iter ( ) . map ( Into :: into) ;
2883
- let n = self . generics_of ( def_id) . count ( ) ;
2884
- debug_assert_eq ! (
2885
- ( n, Some ( n) ) ,
2886
- substs. size_hint( ) ,
2887
- "wrong number of generic parameters for {def_id:?}: {:?} \n Did you accidentally include the self-type in the params list?" ,
2888
- substs. collect:: <Vec <_>>( ) ,
2889
- ) ;
2890
- let substs = self . mk_substs ( substs) ;
2886
+ let substs = self . check_substs ( def_id, substs) ;
2891
2887
ty:: AliasTy { def_id, substs, _use_mk_alias_ty_instead : ( ) }
2892
2888
}
2893
2889
0 commit comments