@@ -18,7 +18,7 @@ use crate::thir::Thir;
18
18
use crate :: traits;
19
19
use crate :: ty:: query:: { self , TyCtxtAt } ;
20
20
use crate :: ty:: {
21
- self , AdtDef , AdtDefData , AdtKind , AliasTy , Binder , BindingMode , BoundVar , CanonicalPolyFnSig ,
21
+ self , AdtDef , AdtDefData , AdtKind , Binder , BindingMode , BoundVar , CanonicalPolyFnSig ,
22
22
ClosureSizeProfileData , Const , ConstS , DefIdTree , FloatTy , FloatVar , FloatVid ,
23
23
GenericParamDefKind , InferTy , IntTy , IntVar , IntVid , List , ParamConst , ParamTy ,
24
24
PolyExistentialPredicate , PolyFnSig , Predicate , PredicateKind , Region , RegionKind , ReprOptions ,
@@ -2591,12 +2591,7 @@ impl<'tcx> TyCtxt<'tcx> {
2591
2591
2592
2592
#[ inline]
2593
2593
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) ) )
2600
2595
}
2601
2596
2602
2597
#[ inline]
@@ -2867,6 +2862,23 @@ impl<'tcx> TyCtxt<'tcx> {
2867
2862
ty:: TraitRef :: new ( trait_def_id, substs)
2868
2863
}
2869
2864
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
+
2870
2882
pub fn mk_bound_variable_kinds <
2871
2883
I : InternAs < ty:: BoundVariableKind , & ' tcx List < ty:: BoundVariableKind > > ,
2872
2884
> (
0 commit comments