@@ -31,6 +31,8 @@ use crate::infer::relate::{Relate, StructurallyRelateAliases, TypeRelation};
3131use rustc_middle:: bug;
3232use rustc_middle:: ty:: { Const , ImplSubject } ;
3333
34+ use crate :: traits:: Obligation ;
35+
3436/// Whether we should define opaque types or just treat them opaquely.
3537///
3638/// Currently only used to prevent predicate matching from matching anything
@@ -119,10 +121,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
119121 self . param_env ,
120122 define_opaque_types,
121123 ) ;
122- fields
123- . sup ( )
124- . relate ( expected, actual)
125- . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
124+ fields. sup ( ) . relate ( expected, actual) ?;
125+ Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
126126 }
127127
128128 /// Makes `expected <: actual`.
@@ -141,10 +141,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
141141 self . param_env ,
142142 define_opaque_types,
143143 ) ;
144- fields
145- . sub ( )
146- . relate ( expected, actual)
147- . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
144+ fields. sub ( ) . relate ( expected, actual) ?;
145+ Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
148146 }
149147
150148 /// Makes `expected == actual`.
@@ -163,10 +161,22 @@ impl<'a, 'tcx> At<'a, 'tcx> {
163161 self . param_env ,
164162 define_opaque_types,
165163 ) ;
166- fields
167- . equate ( StructurallyRelateAliases :: No )
168- . relate ( expected, actual)
169- . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
164+ fields. equate ( StructurallyRelateAliases :: No ) . relate ( expected, actual) ?;
165+ Ok ( InferOk {
166+ value : ( ) ,
167+ obligations : fields
168+ . obligations
169+ . into_iter ( )
170+ . map ( |goal| {
171+ Obligation :: new (
172+ self . infcx . tcx ,
173+ fields. trace . cause . clone ( ) ,
174+ goal. param_env ,
175+ goal. predicate ,
176+ )
177+ } )
178+ . collect ( ) ,
179+ } )
170180 }
171181
172182 /// Equates `expected` and `found` while structurally relating aliases.
@@ -187,10 +197,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
187197 self . param_env ,
188198 DefineOpaqueTypes :: Yes ,
189199 ) ;
190- fields
191- . equate ( StructurallyRelateAliases :: Yes )
192- . relate ( expected, actual)
193- . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
200+ fields. equate ( StructurallyRelateAliases :: Yes ) . relate ( expected, actual) ?;
201+ Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
194202 }
195203
196204 pub fn relate < T > (
@@ -237,10 +245,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
237245 self . param_env ,
238246 define_opaque_types,
239247 ) ;
240- fields
241- . lub ( )
242- . relate ( expected, actual)
243- . map ( |value| InferOk { value, obligations : fields. obligations } )
248+ let value = fields. lub ( ) . relate ( expected, actual) ?;
249+ Ok ( InferOk { value, obligations : fields. into_obligations ( ) } )
244250 }
245251
246252 /// Computes the greatest-lower-bound, or mutual subtype, of two
@@ -261,10 +267,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
261267 self . param_env ,
262268 define_opaque_types,
263269 ) ;
264- fields
265- . glb ( )
266- . relate ( expected, actual)
267- . map ( |value| InferOk { value, obligations : fields. obligations } )
270+ let value = fields. glb ( ) . relate ( expected, actual) ?;
271+ Ok ( InferOk { value, obligations : fields. into_obligations ( ) } )
268272 }
269273}
270274
0 commit comments