@@ -76,6 +76,7 @@ use rustc_type_ir::TyKind::*;
7676use rustc_type_ir:: WithCachedTypeInfo ;
7777use rustc_type_ir:: { CollectAndApply , Interner , TypeFlags } ;
7878
79+ use std:: assert_matches:: assert_matches;
7980use std:: borrow:: Borrow ;
8081use std:: cmp:: Ordering ;
8182use std:: fmt;
@@ -91,67 +92,124 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9192type DefiningOpaqueTypes =& ' tcx ty:: List < LocalDefId > ;
9293type AdtDef = ty:: AdtDef < ' tcx > ;
9394type GenericArgs = ty:: GenericArgsRef < ' tcx > ;
95+ type GenericArgsSlice =& ' tcx [ ty:: GenericArg < ' tcx > ] ;
9496type GenericArg = ty:: GenericArg < ' tcx > ;
95- type Term = ty:: Term < ' tcx > ;
9697
98+ type Term = ty:: Term < ' tcx > ;
9799type Binder < T : TypeVisitable < TyCtxt < ' tcx > > > =Binder < ' tcx , T > ;
98100type BoundVars =& ' tcx List < ty:: BoundVariableKind > ;
99101type BoundVar = ty:: BoundVariableKind ;
100- type CanonicalVars =CanonicalVarInfos < ' tcx > ;
101102
103+ type CanonicalVars =CanonicalVarInfos < ' tcx > ;
102104type Ty =Ty < ' tcx > ;
103105type Tys =& ' tcx List < Ty < ' tcx > > ;
104- type AliasTy = ty:: AliasTy < ' tcx > ;
105106type ParamTy =ParamTy ;
106107type BoundTy = ty:: BoundTy ;
107108type PlaceholderTy = ty:: PlaceholderType ;
108- type ErrorGuaranteed =ErrorGuaranteed ;
109109
110+ type ErrorGuaranteed =ErrorGuaranteed ;
110111type BoundExistentialPredicates =& ' tcx List < PolyExistentialPredicate < ' tcx > > ;
111112type PolyFnSig =PolyFnSig < ' tcx > ;
112113type AllocId =crate :: mir:: interpret:: AllocId ;
113- type Pat =Pattern < ' tcx > ;
114114
115+ type Pat =Pattern < ' tcx > ;
115116type Const = ty:: Const < ' tcx > ;
116117type AliasConst = ty:: UnevaluatedConst < ' tcx > ;
117118type PlaceholderConst = ty:: PlaceholderConst ;
118119type ParamConst = ty:: ParamConst ;
119120type BoundConst = ty:: BoundVar ;
120121type ValueConst = ty:: ValTree < ' tcx > ;
121- type ExprConst = ty:: Expr < ' tcx > ;
122122
123+ type ExprConst = ty:: Expr < ' tcx > ;
123124type Region =Region < ' tcx > ;
124125type EarlyParamRegion = ty:: EarlyParamRegion ;
125126type LateParamRegion = ty:: LateParamRegion ;
126127type BoundRegion = ty:: BoundRegion ;
127128type InferRegion = ty:: RegionVid ;
128- type PlaceholderRegion = ty:: PlaceholderRegion ;
129129
130+ type PlaceholderRegion = ty:: PlaceholderRegion ;
130131type Predicate =Predicate < ' tcx > ;
131132type TraitPredicate = ty:: TraitPredicate < ' tcx > ;
132133type RegionOutlivesPredicate = ty:: RegionOutlivesPredicate < ' tcx > ;
133134type TypeOutlivesPredicate = ty:: TypeOutlivesPredicate < ' tcx > ;
134135type ProjectionPredicate = ty:: ProjectionPredicate < ' tcx > ;
135- type AliasTerm = ty:: AliasTerm < ' tcx > ;
136136type NormalizesTo = ty:: NormalizesTo < ' tcx > ;
137137type SubtypePredicate = ty:: SubtypePredicate < ' tcx > ;
138138type CoercePredicate = ty:: CoercePredicate < ' tcx > ;
139139type ClosureKind = ty:: ClosureKind ;
140- type Clauses = ty:: Clauses < ' tcx > ;
141140
141+ type Clauses = ty:: Clauses < ' tcx > ;
142142fn mk_canonical_var_infos ( self , infos : & [ ty:: CanonicalVarInfo < Self > ] ) ->Self :: CanonicalVars {
143143self . mk_canonical_var_infos ( infos)
144144}
145145
146146type GenericsOf =& ' tcx ty:: Generics ;
147+
147148fn generics_of ( self , def_id : DefId ) ->& ' tcx ty:: Generics {
148149self . generics_of ( def_id)
149150}
150151
152+ fn type_of_instantiated ( self , def_id : DefId , args : ty:: GenericArgsRef < ' tcx > ) ->Ty < ' tcx > {
153+ self . type_of ( def_id) . instantiate ( self , args)
154+ }
155+
156+ fn alias_ty_kind ( self , alias : ty:: AliasTy < ' tcx > ) -> ty:: AliasTyKind {
157+ match self . def_kind ( alias. def_id ) {
158+ DefKind :: AssocTy =>{
159+ if let DefKind :: Impl { of_trait : false } =self . def_kind ( self . parent ( alias. def_id ) )
160+ {
161+ ty:: Inherent
162+ } else {
163+ ty:: Projection
164+ }
165+ }
166+ DefKind :: OpaqueTy => ty:: Opaque ,
167+ DefKind :: TyAlias => ty:: Weak ,
168+ kind =>bug ! ( "unexpected DefKind in AliasTy: {kind:?}" ) ,
169+ }
170+ }
171+
172+ fn alias_term_kind ( self , alias : ty:: AliasTerm < ' tcx > ) -> ty:: AliasTermKind {
173+ match self . def_kind ( alias. def_id ) {
174+ DefKind :: AssocTy =>{
175+ if let DefKind :: Impl { of_trait : false } =self . def_kind ( self . parent ( alias. def_id ) )
176+ {
177+ ty:: AliasTermKind :: InherentTy
178+ } else {
179+ ty:: AliasTermKind :: ProjectionTy
180+ }
181+ }
182+ DefKind :: OpaqueTy => ty:: AliasTermKind :: OpaqueTy ,
183+ DefKind :: TyAlias => ty:: AliasTermKind :: WeakTy ,
184+ DefKind :: AssocConst => ty:: AliasTermKind :: ProjectionConst ,
185+ DefKind :: AnonConst => ty:: AliasTermKind :: UnevaluatedConst ,
186+ kind =>bug ! ( "unexpected DefKind in AliasTy: {kind:?}" ) ,
187+ }
188+ }
189+
190+ fn trait_ref_and_own_args_for_alias (
191+ self ,
192+ def_id : Self :: DefId ,
193+ args : Self :: GenericArgs ,
194+ ) ->( rustc_type_ir:: TraitRef < Self > , Self :: GenericArgsSlice ) {
195+ assert_matches ! ( self . def_kind( def_id) , DefKind :: AssocTy |DefKind :: AssocConst ) ;
196+ let trait_def_id =self . parent ( def_id) ;
197+ assert_matches ! ( self . def_kind( trait_def_id) , DefKind :: Trait ) ;
198+ let trait_generics =self . generics_of ( trait_def_id) ;
199+ (
200+ ty:: TraitRef :: new ( self , trait_def_id, args. truncate_to ( self , trait_generics) ) ,
201+ & args[ trait_generics. count ( ) ..] ,
202+ )
203+ }
204+
151205fn mk_args ( self , args : & [ Self :: GenericArg ] ) ->Self :: GenericArgs {
152206self . mk_args ( args)
153207}
154208
209+ fn mk_args_from_iter ( self , args : impl Iterator < Item =Self :: GenericArg > ) ->Self :: GenericArgs {
210+ self . mk_args_from_iter ( args)
211+ }
212+
155213fn check_and_mk_args (
156214self ,
157215def_id : DefId ,