26
26
//! things. (That system should probably be refactored.)
27
27
28
28
use rustc_middle:: bug;
29
+ use rustc_middle:: ty:: relate:: solver_relating:: RelateExt as NextSolverRelate ;
29
30
use rustc_middle:: ty:: { Const , ImplSubject } ;
30
31
31
32
use super :: * ;
32
33
use crate :: infer:: relate:: { Relate , TypeRelation } ;
33
34
use crate :: traits:: Obligation ;
35
+ use crate :: traits:: solve:: Goal ;
34
36
35
37
/// Whether we should define opaque types or just treat them opaquely.
36
38
///
@@ -109,14 +111,25 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109
111
where
110
112
T : ToTrace < ' tcx > ,
111
113
{
112
- let mut fields = CombineFields :: new (
113
- self . infcx ,
114
- ToTrace :: to_trace ( self . cause , expected, actual) ,
115
- self . param_env ,
116
- define_opaque_types,
117
- ) ;
118
- fields. sup ( ) . relate ( expected, actual) ?;
119
- Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
114
+ if self . infcx . next_trait_solver ( ) {
115
+ NextSolverRelate :: relate (
116
+ self . infcx ,
117
+ self . param_env ,
118
+ expected,
119
+ ty:: Contravariant ,
120
+ actual,
121
+ )
122
+ . map ( |goals| self . goals_to_obligations ( goals) )
123
+ } else {
124
+ let mut fields = CombineFields :: new (
125
+ self . infcx ,
126
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
127
+ self . param_env ,
128
+ define_opaque_types,
129
+ ) ;
130
+ fields. sup ( ) . relate ( expected, actual) ?;
131
+ Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
132
+ }
120
133
}
121
134
122
135
/// Makes `expected <: actual`.
@@ -129,14 +142,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
129
142
where
130
143
T : ToTrace < ' tcx > ,
131
144
{
132
- let mut fields = CombineFields :: new (
133
- self . infcx ,
134
- ToTrace :: to_trace ( self . cause , expected, actual) ,
135
- self . param_env ,
136
- define_opaque_types,
137
- ) ;
138
- fields. sub ( ) . relate ( expected, actual) ?;
139
- Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
145
+ if self . infcx . next_trait_solver ( ) {
146
+ NextSolverRelate :: relate ( self . infcx , self . param_env , expected, ty:: Covariant , actual)
147
+ . map ( |goals| self . goals_to_obligations ( goals) )
148
+ } else {
149
+ let mut fields = CombineFields :: new (
150
+ self . infcx ,
151
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
152
+ self . param_env ,
153
+ define_opaque_types,
154
+ ) ;
155
+ fields. sub ( ) . relate ( expected, actual) ?;
156
+ Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
157
+ }
140
158
}
141
159
142
160
/// Makes `expected == actual`.
@@ -168,23 +186,29 @@ impl<'a, 'tcx> At<'a, 'tcx> {
168
186
where
169
187
T : Relate < TyCtxt < ' tcx > > ,
170
188
{
171
- let mut fields = CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
172
- fields. equate ( ) . 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
- } )
189
+ if self . infcx . next_trait_solver ( ) {
190
+ NextSolverRelate :: relate ( self . infcx , self . param_env , expected, ty:: Invariant , actual)
191
+ . map ( |goals| self . goals_to_obligations ( goals) )
192
+ } else {
193
+ let mut fields =
194
+ CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
195
+ fields. equate ( ) . relate ( expected, actual) ?;
196
+ Ok ( InferOk {
197
+ value : ( ) ,
198
+ obligations : fields
199
+ . goals
200
+ . into_iter ( )
201
+ . map ( |goal| {
202
+ Obligation :: new (
203
+ self . infcx . tcx ,
204
+ fields. trace . cause . clone ( ) ,
205
+ goal. param_env ,
206
+ goal. predicate ,
207
+ )
208
+ } )
209
+ . collect ( ) ,
210
+ } )
211
+ }
188
212
}
189
213
190
214
pub fn relate < T > (
@@ -256,6 +280,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
256
280
let value = fields. glb ( ) . relate ( expected, actual) ?;
257
281
Ok ( InferOk { value, obligations : fields. into_obligations ( ) } )
258
282
}
283
+
284
+ fn goals_to_obligations (
285
+ & self ,
286
+ goals : Vec < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
287
+ ) -> InferOk < ' tcx , ( ) > {
288
+ InferOk {
289
+ value : ( ) ,
290
+ obligations : goals
291
+ . into_iter ( )
292
+ . map ( |goal| {
293
+ Obligation :: new (
294
+ self . infcx . tcx ,
295
+ self . cause . clone ( ) ,
296
+ goal. param_env ,
297
+ goal. predicate ,
298
+ )
299
+ } )
300
+ . collect ( ) ,
301
+ }
302
+ }
259
303
}
260
304
261
305
impl < ' tcx > ToTrace < ' tcx > for ImplSubject < ' tcx > {
0 commit comments