@@ -31,6 +31,8 @@ use crate::infer::relate::{Relate, StructurallyRelateAliases, TypeRelation};
31
31
use rustc_middle:: bug;
32
32
use rustc_middle:: ty:: { Const , ImplSubject } ;
33
33
34
+ use crate :: traits:: Obligation ;
35
+
34
36
/// Whether we should define opaque types or just treat them opaquely.
35
37
///
36
38
/// Currently only used to prevent predicate matching from matching anything
@@ -119,10 +121,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
119
121
self . param_env ,
120
122
define_opaque_types,
121
123
) ;
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 ( ) } )
126
126
}
127
127
128
128
/// Makes `expected <: actual`.
@@ -141,10 +141,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
141
141
self . param_env ,
142
142
define_opaque_types,
143
143
) ;
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 ( ) } )
148
146
}
149
147
150
148
/// Makes `expected == actual`.
@@ -163,10 +161,22 @@ impl<'a, 'tcx> At<'a, 'tcx> {
163
161
self . param_env ,
164
162
define_opaque_types,
165
163
) ;
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
+ } )
170
180
}
171
181
172
182
/// Equates `expected` and `found` while structurally relating aliases.
@@ -187,10 +197,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
187
197
self . param_env ,
188
198
DefineOpaqueTypes :: Yes ,
189
199
) ;
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 ( ) } )
194
202
}
195
203
196
204
pub fn relate < T > (
@@ -237,10 +245,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
237
245
self . param_env ,
238
246
define_opaque_types,
239
247
) ;
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 ( ) } )
244
250
}
245
251
246
252
/// Computes the greatest-lower-bound, or mutual subtype, of two
@@ -261,10 +267,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
261
267
self . param_env ,
262
268
define_opaque_types,
263
269
) ;
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 ( ) } )
268
272
}
269
273
}
270
274
0 commit comments