@@ -18,7 +18,7 @@ use crate::thir::Thir;
1818use crate :: traits;
1919use crate :: ty:: query:: { self , TyCtxtAt } ;
2020use crate :: ty:: {
21- self , AdtDef , AdtDefData , AdtKind , AliasTy , Binder , BindingMode , BoundVar , CanonicalPolyFnSig ,
21+ self , AdtDef , AdtDefData , AdtKind , Binder , BindingMode , BoundVar , CanonicalPolyFnSig ,
2222 ClosureSizeProfileData , Const , ConstS , DefIdTree , FloatTy , FloatVar , FloatVid ,
2323 GenericParamDefKind , InferTy , IntTy , IntVar , IntVid , List , ParamConst , ParamTy ,
2424 PolyExistentialPredicate , PolyFnSig , Predicate , PredicateKind , Region , RegionKind , ReprOptions ,
@@ -2591,12 +2591,7 @@ impl<'tcx> TyCtxt<'tcx> {
25912591
25922592 #[ inline]
25932593 pub fn mk_projection ( self , item_def_id : DefId , substs : SubstsRef < ' tcx > ) -> Ty < ' tcx > {
2594- debug_assert_eq ! (
2595- self . generics_of( item_def_id) . count( ) ,
2596- substs. len( ) ,
2597- "wrong number of generic parameters for {item_def_id:?}: {substs:?}" ,
2598- ) ;
2599- self . mk_ty ( Alias ( ty:: Projection , AliasTy { def_id : item_def_id, substs } ) )
2594+ self . mk_ty ( Alias ( ty:: Projection , self . mk_alias_ty ( item_def_id, substs) ) )
26002595 }
26012596
26022597 #[ inline]
@@ -2867,6 +2862,23 @@ impl<'tcx> TyCtxt<'tcx> {
28672862 ty:: TraitRef :: new ( trait_def_id, substs)
28682863 }
28692864
2865+ pub fn mk_alias_ty (
2866+ self ,
2867+ def_id : DefId ,
2868+ substs : impl IntoIterator < Item = impl Into < GenericArg < ' tcx > > > ,
2869+ ) -> ty:: AliasTy < ' tcx > {
2870+ let substs = substs. into_iter ( ) . map ( Into :: into) ;
2871+ let n = self . generics_of ( def_id) . count ( ) ;
2872+ debug_assert_eq ! (
2873+ ( n, Some ( n) ) ,
2874+ substs. size_hint( ) ,
2875+ "wrong number of generic parameters for {def_id:?}: {:?} \n Did you accidentally include the self-type in the params list?" ,
2876+ substs. collect:: <Vec <_>>( ) ,
2877+ ) ;
2878+ let substs = self . mk_substs ( substs) ;
2879+ ty:: AliasTy { def_id, substs }
2880+ }
2881+
28702882 pub fn mk_bound_variable_kinds <
28712883 I : InternAs < ty:: BoundVariableKind , & ' tcx List < ty:: BoundVariableKind > > ,
28722884 > (
0 commit comments