@@ -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> {
9192 type DefiningOpaqueTypes = & ' tcx ty:: List < LocalDefId > ;
9293 type AdtDef = ty:: AdtDef < ' tcx > ;
9394 type GenericArgs = ty:: GenericArgsRef < ' tcx > ;
95+ type GenericArgsSlice = & ' tcx [ ty:: GenericArg < ' tcx > ] ;
9496 type GenericArg = ty:: GenericArg < ' tcx > ;
95- type Term = ty:: Term < ' tcx > ;
9697
98+ type Term = ty:: Term < ' tcx > ;
9799 type Binder < T : TypeVisitable < TyCtxt < ' tcx > > > = Binder < ' tcx , T > ;
98100 type BoundVars = & ' tcx List < ty:: BoundVariableKind > ;
99101 type BoundVar = ty:: BoundVariableKind ;
100- type CanonicalVars = CanonicalVarInfos < ' tcx > ;
101102
103+ type CanonicalVars = CanonicalVarInfos < ' tcx > ;
102104 type Ty = Ty < ' tcx > ;
103105 type Tys = & ' tcx List < Ty < ' tcx > > ;
104- type AliasTy = ty:: AliasTy < ' tcx > ;
105106 type ParamTy = ParamTy ;
106107 type BoundTy = ty:: BoundTy ;
107108 type PlaceholderTy = ty:: PlaceholderType ;
108- type ErrorGuaranteed = ErrorGuaranteed ;
109109
110+ type ErrorGuaranteed = ErrorGuaranteed ;
110111 type BoundExistentialPredicates = & ' tcx List < PolyExistentialPredicate < ' tcx > > ;
111112 type PolyFnSig = PolyFnSig < ' tcx > ;
112113 type AllocId = crate :: mir:: interpret:: AllocId ;
113- type Pat = Pattern < ' tcx > ;
114114
115+ type Pat = Pattern < ' tcx > ;
115116 type Const = ty:: Const < ' tcx > ;
116117 type AliasConst = ty:: UnevaluatedConst < ' tcx > ;
117118 type PlaceholderConst = ty:: PlaceholderConst ;
118119 type ParamConst = ty:: ParamConst ;
119120 type BoundConst = ty:: BoundVar ;
120121 type ValueConst = ty:: ValTree < ' tcx > ;
121- type ExprConst = ty:: Expr < ' tcx > ;
122122
123+ type ExprConst = ty:: Expr < ' tcx > ;
123124 type Region = Region < ' tcx > ;
124125 type EarlyParamRegion = ty:: EarlyParamRegion ;
125126 type LateParamRegion = ty:: LateParamRegion ;
126127 type BoundRegion = ty:: BoundRegion ;
127128 type InferRegion = ty:: RegionVid ;
128- type PlaceholderRegion = ty:: PlaceholderRegion ;
129129
130+ type PlaceholderRegion = ty:: PlaceholderRegion ;
130131 type Predicate = Predicate < ' tcx > ;
131132 type TraitPredicate = ty:: TraitPredicate < ' tcx > ;
132133 type RegionOutlivesPredicate = ty:: RegionOutlivesPredicate < ' tcx > ;
133134 type TypeOutlivesPredicate = ty:: TypeOutlivesPredicate < ' tcx > ;
134135 type ProjectionPredicate = ty:: ProjectionPredicate < ' tcx > ;
135- type AliasTerm = ty:: AliasTerm < ' tcx > ;
136136 type NormalizesTo = ty:: NormalizesTo < ' tcx > ;
137137 type SubtypePredicate = ty:: SubtypePredicate < ' tcx > ;
138138 type CoercePredicate = ty:: CoercePredicate < ' tcx > ;
139139 type ClosureKind = ty:: ClosureKind ;
140- type Clauses = ty:: Clauses < ' tcx > ;
141140
141+ type Clauses = ty:: Clauses < ' tcx > ;
142142 fn mk_canonical_var_infos ( self , infos : & [ ty:: CanonicalVarInfo < Self > ] ) -> Self :: CanonicalVars {
143143 self . mk_canonical_var_infos ( infos)
144144 }
145145
146146 type GenericsOf = & ' tcx ty:: Generics ;
147+
147148 fn generics_of ( self , def_id : DefId ) -> & ' tcx ty:: Generics {
148149 self . 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+
151205 fn mk_args ( self , args : & [ Self :: GenericArg ] ) -> Self :: GenericArgs {
152206 self . 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+
155213 fn check_and_mk_args (
156214 self ,
157215 def_id : DefId ,
0 commit comments