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
///
@@ -108,14 +110,25 @@ impl<'a, 'tcx> At<'a, 'tcx> {
108
110
where
109
111
T : ToTrace < ' tcx > ,
110
112
{
111
- let mut fields = CombineFields :: new (
112
- self . infcx ,
113
- ToTrace :: to_trace ( self . cause , expected, actual) ,
114
- self . param_env ,
115
- define_opaque_types,
116
- ) ;
117
- fields. sup ( ) . relate ( expected, actual) ?;
118
- Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
113
+ if self . infcx . next_trait_solver ( ) {
114
+ NextSolverRelate :: relate (
115
+ self . infcx ,
116
+ self . param_env ,
117
+ expected,
118
+ ty:: Contravariant ,
119
+ actual,
120
+ )
121
+ . map ( |goals| self . goals_to_obligations ( goals) )
122
+ } else {
123
+ let mut fields = CombineFields :: new (
124
+ self . infcx ,
125
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
126
+ self . param_env ,
127
+ define_opaque_types,
128
+ ) ;
129
+ fields. sup ( ) . relate ( expected, actual) ?;
130
+ Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
131
+ }
119
132
}
120
133
121
134
/// Makes `expected <: actual`.
@@ -128,14 +141,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
128
141
where
129
142
T : ToTrace < ' tcx > ,
130
143
{
131
- let mut fields = CombineFields :: new (
132
- self . infcx ,
133
- ToTrace :: to_trace ( self . cause , expected, actual) ,
134
- self . param_env ,
135
- define_opaque_types,
136
- ) ;
137
- fields. sub ( ) . relate ( expected, actual) ?;
138
- Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
144
+ if self . infcx . next_trait_solver ( ) {
145
+ NextSolverRelate :: relate ( self . infcx , self . param_env , expected, ty:: Covariant , actual)
146
+ . map ( |goals| self . goals_to_obligations ( goals) )
147
+ } else {
148
+ let mut fields = CombineFields :: new (
149
+ self . infcx ,
150
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
151
+ self . param_env ,
152
+ define_opaque_types,
153
+ ) ;
154
+ fields. sub ( ) . relate ( expected, actual) ?;
155
+ Ok ( InferOk { value : ( ) , obligations : fields. into_obligations ( ) } )
156
+ }
139
157
}
140
158
141
159
/// Makes `expected == actual`.
@@ -167,23 +185,29 @@ impl<'a, 'tcx> At<'a, 'tcx> {
167
185
where
168
186
T : Relate < TyCtxt < ' tcx > > ,
169
187
{
170
- let mut fields = CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
171
- fields. equate ( ) . 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
- } )
188
+ if self . infcx . next_trait_solver ( ) {
189
+ NextSolverRelate :: relate ( self . infcx , self . param_env , expected, ty:: Invariant , actual)
190
+ . map ( |goals| self . goals_to_obligations ( goals) )
191
+ } else {
192
+ let mut fields =
193
+ CombineFields :: new ( self . infcx , trace, self . param_env , define_opaque_types) ;
194
+ fields. equate ( ) . relate ( expected, actual) ?;
195
+ Ok ( InferOk {
196
+ value : ( ) ,
197
+ obligations : fields
198
+ . goals
199
+ . into_iter ( )
200
+ . map ( |goal| {
201
+ Obligation :: new (
202
+ self . infcx . tcx ,
203
+ fields. trace . cause . clone ( ) ,
204
+ goal. param_env ,
205
+ goal. predicate ,
206
+ )
207
+ } )
208
+ . collect ( ) ,
209
+ } )
210
+ }
187
211
}
188
212
189
213
pub fn relate < T > (
@@ -255,6 +279,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
255
279
let value = fields. glb ( ) . relate ( expected, actual) ?;
256
280
Ok ( InferOk { value, obligations : fields. into_obligations ( ) } )
257
281
}
282
+
283
+ fn goals_to_obligations (
284
+ & self ,
285
+ goals : Vec < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
286
+ ) -> InferOk < ' tcx , ( ) > {
287
+ InferOk {
288
+ value : ( ) ,
289
+ obligations : goals
290
+ . into_iter ( )
291
+ . map ( |goal| {
292
+ Obligation :: new (
293
+ self . infcx . tcx ,
294
+ self . cause . clone ( ) ,
295
+ goal. param_env ,
296
+ goal. predicate ,
297
+ )
298
+ } )
299
+ . collect ( ) ,
300
+ }
301
+ }
258
302
}
259
303
260
304
impl < ' tcx > ToTrace < ' tcx > for ImplSubject < ' tcx > {
0 commit comments