@@ -2570,18 +2570,30 @@ impl<'tcx> TyCtxt<'tcx> {
25702570 def_id : DefId ,
25712571 substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
25722572 ) -> 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) ;
25822574 self . mk_ty ( FnDef ( def_id, substs) )
25832575 }
25842576
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+
25852597 #[ inline]
25862598 pub fn mk_fn_ptr ( self , fty : PolyFnSig < ' tcx > ) -> Ty < ' tcx > {
25872599 self . mk_ty ( FnPtr ( fty) )
@@ -2862,15 +2874,7 @@ impl<'tcx> TyCtxt<'tcx> {
28622874 trait_def_id : DefId ,
28632875 substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
28642876 ) -> 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) ;
28742878 ty:: TraitRef { def_id : trait_def_id, substs, _use_mk_trait_ref_instead : ( ) }
28752879 }
28762880
@@ -2879,15 +2883,7 @@ impl<'tcx> TyCtxt<'tcx> {
28792883 def_id : DefId ,
28802884 substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
28812885 ) -> 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) ;
28912887 ty:: AliasTy { def_id, substs, _use_mk_alias_ty_instead : ( ) }
28922888 }
28932889
0 commit comments