2525//! sometimes useful when the types of `c` and `d` are not traceable
2626//! things. (That system should probably be refactored.)
2727
28+ use relate:: lattice:: { LatticeOp , LatticeOpKind } ;
2829use rustc_middle:: bug;
2930use rustc_middle:: ty:: { Const , ImplSubject } ;
3031
3132use super :: * ;
33+ use crate :: infer:: relate:: type_relating:: TypeRelating ;
3234use crate :: infer:: relate:: { Relate , StructurallyRelateAliases , TypeRelation } ;
33- use crate :: traits:: Obligation ;
3435
3536/// Whether we should define opaque types or just treat them opaquely.
3637///
@@ -109,14 +110,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109110 where
110111 T : ToTrace < ' tcx > ,
111112 {
112- let mut fields = CombineFields :: new (
113+ let mut op = TypeRelating :: new (
113114 self . infcx ,
114115 ToTrace :: to_trace ( self . cause , expected, actual) ,
115116 self . param_env ,
116117 define_opaque_types,
118+ StructurallyRelateAliases :: No ,
119+ ty:: Contravariant ,
117120 ) ;
118- fields . sup ( ) . relate ( expected, actual) ?;
119- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
121+ op . relate ( expected, actual) ?;
122+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
120123 }
121124
122125 /// Makes `expected <: actual`.
@@ -129,14 +132,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
129132 where
130133 T : ToTrace < ' tcx > ,
131134 {
132- let mut fields = CombineFields :: new (
135+ let mut op = TypeRelating :: new (
133136 self . infcx ,
134137 ToTrace :: to_trace ( self . cause , expected, actual) ,
135138 self . param_env ,
136139 define_opaque_types,
140+ StructurallyRelateAliases :: No ,
141+ ty:: Covariant ,
137142 ) ;
138- fields . sub ( ) . relate ( expected, actual) ?;
139- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
143+ op . relate ( expected, actual) ?;
144+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
140145 }
141146
142147 /// Makes `expected == actual`.
@@ -168,23 +173,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
168173 where
169174 T : Relate < TyCtxt < ' tcx > > ,
170175 {
171- let mut fields = CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
172- fields. equate ( StructurallyRelateAliases :: No ) . relate ( expected, actual) ?;
173- Ok ( InferOk {
174- value : ( ) ,
175- obligations : fields
176- . goals
177- . into_iter ( )
178- . map ( |goal| {
179- Obligation :: new (
180- self . infcx . tcx ,
181- fields. trace . cause . clone ( ) ,
182- goal. param_env ,
183- goal. predicate ,
184- )
185- } )
186- . collect ( ) ,
187- } )
176+ let mut op = TypeRelating :: new (
177+ self . infcx ,
178+ trace,
179+ self . param_env ,
180+ define_opaque_types,
181+ StructurallyRelateAliases :: No ,
182+ ty:: Invariant ,
183+ ) ;
184+ op. relate ( expected, actual) ?;
185+ Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
188186 }
189187
190188 /// Equates `expected` and `found` while structurally relating aliases.
@@ -199,14 +197,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
199197 T : ToTrace < ' tcx > ,
200198 {
201199 assert ! ( self . infcx. next_trait_solver( ) ) ;
202- let mut fields = CombineFields :: new (
200+ let mut op = TypeRelating :: new (
203201 self . infcx ,
204202 ToTrace :: to_trace ( self . cause , expected, actual) ,
205203 self . param_env ,
206204 DefineOpaqueTypes :: Yes ,
205+ StructurallyRelateAliases :: Yes ,
206+ ty:: Invariant ,
207207 ) ;
208- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
209- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
208+ op . relate ( expected, actual) ?;
209+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
210210 }
211211
212212 pub fn relate < T > (
@@ -243,19 +243,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
243243 where
244244 T : Relate < TyCtxt < ' tcx > > ,
245245 {
246- let mut fields = CombineFields :: new (
246+ let mut op = TypeRelating :: new (
247247 self . infcx ,
248248 TypeTrace :: dummy ( self . cause ) ,
249249 self . param_env ,
250250 DefineOpaqueTypes :: Yes ,
251- ) ;
252- fields. sub ( ) . relate_with_variance (
251+ StructurallyRelateAliases :: No ,
253252 variance,
254- ty:: VarianceDiagInfo :: default ( ) ,
255- expected,
256- actual,
257- ) ?;
258- Ok ( fields. goals )
253+ ) ;
254+ op. relate ( expected, actual) ?;
255+ Ok ( op. into_obligations ( ) . into_iter ( ) . map ( |o| o. into ( ) ) . collect ( ) )
259256 }
260257
261258 /// Used in the new solver since we don't care about tracking an `ObligationCause`.
@@ -267,14 +264,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
267264 where
268265 T : Relate < TyCtxt < ' tcx > > ,
269266 {
270- let mut fields = CombineFields :: new (
267+ let mut op = TypeRelating :: new (
271268 self . infcx ,
272269 TypeTrace :: dummy ( self . cause ) ,
273270 self . param_env ,
274271 DefineOpaqueTypes :: Yes ,
272+ StructurallyRelateAliases :: Yes ,
273+ ty:: Invariant ,
275274 ) ;
276- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
277- Ok ( fields . goals )
275+ op . relate ( expected, actual) ?;
276+ Ok ( op . into_obligations ( ) . into_iter ( ) . map ( |o| o . into ( ) ) . collect ( ) )
278277 }
279278
280279 /// Computes the least-upper-bound, or mutual supertype, of two
@@ -291,14 +290,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
291290 where
292291 T : ToTrace < ' tcx > ,
293292 {
294- let mut fields = CombineFields :: new (
293+ let mut op = LatticeOp :: new (
295294 self . infcx ,
296295 ToTrace :: to_trace ( self . cause , expected, actual) ,
297296 self . param_env ,
298297 define_opaque_types,
298+ LatticeOpKind :: Lub ,
299299 ) ;
300- let value = fields . lub ( ) . relate ( expected, actual) ?;
301- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
300+ let value = op . relate ( expected, actual) ?;
301+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
302302 }
303303
304304 /// Computes the greatest-lower-bound, or mutual subtype, of two
@@ -313,14 +313,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
313313 where
314314 T : ToTrace < ' tcx > ,
315315 {
316- let mut fields = CombineFields :: new (
316+ let mut op = LatticeOp :: new (
317317 self . infcx ,
318318 ToTrace :: to_trace ( self . cause , expected, actual) ,
319319 self . param_env ,
320320 define_opaque_types,
321+ LatticeOpKind :: Glb ,
321322 ) ;
322- let value = fields . glb ( ) . relate ( expected, actual) ?;
323- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
323+ let value = op . relate ( expected, actual) ?;
324+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
324325 }
325326}
326327
0 commit comments