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///
@@ -108,14 +109,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
108109 where
109110 T : ToTrace < ' tcx > ,
110111 {
111- let mut fields = CombineFields :: new (
112+ let mut op = TypeRelating :: new (
112113 self . infcx ,
113114 ToTrace :: to_trace ( self . cause , expected, actual) ,
114115 self . param_env ,
115116 define_opaque_types,
117+ StructurallyRelateAliases :: No ,
118+ ty:: Contravariant ,
116119 ) ;
117- fields . sup ( ) . relate ( expected, actual) ?;
118- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
120+ op . relate ( expected, actual) ?;
121+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
119122 }
120123
121124 /// Makes `expected <: actual`.
@@ -128,14 +131,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
128131 where
129132 T : ToTrace < ' tcx > ,
130133 {
131- let mut fields = CombineFields :: new (
134+ let mut op = TypeRelating :: new (
132135 self . infcx ,
133136 ToTrace :: to_trace ( self . cause , expected, actual) ,
134137 self . param_env ,
135138 define_opaque_types,
139+ StructurallyRelateAliases :: No ,
140+ ty:: Covariant ,
136141 ) ;
137- fields . sub ( ) . relate ( expected, actual) ?;
138- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
142+ op . relate ( expected, actual) ?;
143+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
139144 }
140145
141146 /// Makes `expected == actual`.
@@ -167,23 +172,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
167172 where
168173 T : Relate < TyCtxt < ' tcx > > ,
169174 {
170- let mut fields = CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
171- fields. equate ( StructurallyRelateAliases :: No ) . relate ( expected, actual) ?;
172- Ok ( InferOk {
173- value : ( ) ,
174- obligations : fields
175- . goals
176- . into_iter ( )
177- . map ( |goal| {
178- Obligation :: new (
179- self . infcx . tcx ,
180- fields. trace . cause . clone ( ) ,
181- goal. param_env ,
182- goal. predicate ,
183- )
184- } )
185- . collect ( ) ,
186- } )
175+ let mut op = TypeRelating :: new (
176+ self . infcx ,
177+ trace,
178+ self . param_env ,
179+ define_opaque_types,
180+ StructurallyRelateAliases :: No ,
181+ ty:: Invariant ,
182+ ) ;
183+ op. relate ( expected, actual) ?;
184+ Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
187185 }
188186
189187 /// Equates `expected` and `found` while structurally relating aliases.
@@ -198,14 +196,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
198196 T : ToTrace < ' tcx > ,
199197 {
200198 assert ! ( self . infcx. next_trait_solver( ) ) ;
201- let mut fields = CombineFields :: new (
199+ let mut op = TypeRelating :: new (
202200 self . infcx ,
203201 ToTrace :: to_trace ( self . cause , expected, actual) ,
204202 self . param_env ,
205203 DefineOpaqueTypes :: Yes ,
204+ StructurallyRelateAliases :: Yes ,
205+ ty:: Invariant ,
206206 ) ;
207- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
208- Ok ( InferOk { value : ( ) , obligations : fields . into_obligations ( ) } )
207+ op . relate ( expected, actual) ?;
208+ Ok ( InferOk { value : ( ) , obligations : op . into_obligations ( ) } )
209209 }
210210
211211 pub fn relate < T > (
@@ -242,19 +242,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
242242 where
243243 T : Relate < TyCtxt < ' tcx > > ,
244244 {
245- let mut fields = CombineFields :: new (
245+ let mut op = TypeRelating :: new (
246246 self . infcx ,
247247 TypeTrace :: dummy ( self . cause ) ,
248248 self . param_env ,
249249 DefineOpaqueTypes :: Yes ,
250- ) ;
251- fields. sub ( ) . relate_with_variance (
250+ StructurallyRelateAliases :: No ,
252251 variance,
253- ty:: VarianceDiagInfo :: default ( ) ,
254- expected,
255- actual,
256- ) ?;
257- Ok ( fields. goals )
252+ ) ;
253+ op. relate ( expected, actual) ?;
254+ Ok ( op. into_obligations ( ) . into_iter ( ) . map ( |o| o. into ( ) ) . collect ( ) )
258255 }
259256
260257 /// Used in the new solver since we don't care about tracking an `ObligationCause`.
@@ -266,14 +263,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
266263 where
267264 T : Relate < TyCtxt < ' tcx > > ,
268265 {
269- let mut fields = CombineFields :: new (
266+ let mut op = TypeRelating :: new (
270267 self . infcx ,
271268 TypeTrace :: dummy ( self . cause ) ,
272269 self . param_env ,
273270 DefineOpaqueTypes :: Yes ,
271+ StructurallyRelateAliases :: Yes ,
272+ ty:: Invariant ,
274273 ) ;
275- fields . equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
276- Ok ( fields . goals )
274+ op . relate ( expected, actual) ?;
275+ Ok ( op . into_obligations ( ) . into_iter ( ) . map ( |o| o . into ( ) ) . collect ( ) )
277276 }
278277
279278 /// Computes the least-upper-bound, or mutual supertype, of two
@@ -290,14 +289,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
290289 where
291290 T : ToTrace < ' tcx > ,
292291 {
293- let mut fields = CombineFields :: new (
292+ let mut op = LatticeOp :: new (
294293 self . infcx ,
295294 ToTrace :: to_trace ( self . cause , expected, actual) ,
296295 self . param_env ,
297296 define_opaque_types,
297+ LatticeOpKind :: Lub ,
298298 ) ;
299- let value = fields . lub ( ) . relate ( expected, actual) ?;
300- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
299+ let value = op . relate ( expected, actual) ?;
300+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
301301 }
302302
303303 /// Computes the greatest-lower-bound, or mutual subtype, of two
@@ -312,14 +312,15 @@ impl<'a, 'tcx> At<'a, 'tcx> {
312312 where
313313 T : ToTrace < ' tcx > ,
314314 {
315- let mut fields = CombineFields :: new (
315+ let mut op = LatticeOp :: new (
316316 self . infcx ,
317317 ToTrace :: to_trace ( self . cause , expected, actual) ,
318318 self . param_env ,
319319 define_opaque_types,
320+ LatticeOpKind :: Glb ,
320321 ) ;
321- let value = fields . glb ( ) . relate ( expected, actual) ?;
322- Ok ( InferOk { value, obligations : fields . into_obligations ( ) } )
322+ let value = op . relate ( expected, actual) ?;
323+ Ok ( InferOk { value, obligations : op . into_obligations ( ) } )
323324 }
324325}
325326
0 commit comments