27
27
28
28
use relate:: lattice:: { LatticeOp , LatticeOpKind } ;
29
29
use rustc_middle:: bug;
30
+ use rustc_middle:: ty:: relate:: solver_relating:: RelateExt as NextSolverRelate ;
30
31
use rustc_middle:: ty:: { Const , ImplSubject } ;
31
32
32
33
use super :: * ;
33
34
use crate :: infer:: relate:: type_relating:: TypeRelating ;
34
35
use crate :: infer:: relate:: { Relate , TypeRelation } ;
36
+ use crate :: traits:: Obligation ;
37
+ use crate :: traits:: solve:: Goal ;
35
38
36
39
/// Whether we should define opaque types or just treat them opaquely.
37
40
///
@@ -109,15 +112,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109
112
where
110
113
T : ToTrace < ' tcx > ,
111
114
{
112
- let mut op = TypeRelating :: new (
113
- self . infcx ,
114
- ToTrace :: to_trace ( self . cause , expected, actual) ,
115
- self . param_env ,
116
- define_opaque_types,
117
- ty:: Contravariant ,
118
- ) ;
119
- op. relate ( expected, actual) ?;
120
- Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
115
+ if self . infcx . next_trait_solver {
116
+ NextSolverRelate :: relate (
117
+ self . infcx ,
118
+ self . param_env ,
119
+ expected,
120
+ ty:: Contravariant ,
121
+ actual,
122
+ )
123
+ . map ( |goals| self . goals_to_obligations ( goals) )
124
+ } else {
125
+ let mut op = TypeRelating :: new (
126
+ self . infcx ,
127
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
128
+ self . param_env ,
129
+ define_opaque_types,
130
+ ty:: Contravariant ,
131
+ ) ;
132
+ op. relate ( expected, actual) ?;
133
+ Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
134
+ }
121
135
}
122
136
123
137
/// Makes `expected <: actual`.
@@ -130,15 +144,20 @@ impl<'a, 'tcx> At<'a, 'tcx> {
130
144
where
131
145
T : ToTrace < ' tcx > ,
132
146
{
133
- let mut op = TypeRelating :: new (
134
- self . infcx ,
135
- ToTrace :: to_trace ( self . cause , expected, actual) ,
136
- self . param_env ,
137
- define_opaque_types,
138
- ty:: Covariant ,
139
- ) ;
140
- op. relate ( expected, actual) ?;
141
- Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
147
+ if self . infcx . next_trait_solver {
148
+ NextSolverRelate :: relate ( self . infcx , self . param_env , expected, ty:: Covariant , actual)
149
+ . map ( |goals| self . goals_to_obligations ( goals) )
150
+ } else {
151
+ let mut op = TypeRelating :: new (
152
+ self . infcx ,
153
+ ToTrace :: to_trace ( self . cause , expected, actual) ,
154
+ self . param_env ,
155
+ define_opaque_types,
156
+ ty:: Covariant ,
157
+ ) ;
158
+ op. relate ( expected, actual) ?;
159
+ Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
160
+ }
142
161
}
143
162
144
163
/// Makes `expected == actual`.
@@ -170,15 +189,20 @@ impl<'a, 'tcx> At<'a, 'tcx> {
170
189
where
171
190
T : Relate < TyCtxt < ' tcx > > ,
172
191
{
173
- let mut op = TypeRelating :: new (
174
- self . infcx ,
175
- trace,
176
- self . param_env ,
177
- define_opaque_types,
178
- ty:: Invariant ,
179
- ) ;
180
- op. relate ( expected, actual) ?;
181
- Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
192
+ if self . infcx . next_trait_solver {
193
+ NextSolverRelate :: relate ( self . infcx , self . param_env , expected, ty:: Invariant , actual)
194
+ . map ( |goals| self . goals_to_obligations ( goals) )
195
+ } else {
196
+ let mut op = TypeRelating :: new (
197
+ self . infcx ,
198
+ trace,
199
+ self . param_env ,
200
+ define_opaque_types,
201
+ ty:: Invariant ,
202
+ ) ;
203
+ op. relate ( expected, actual) ?;
204
+ Ok ( InferOk { value : ( ) , obligations : op. into_obligations ( ) } )
205
+ }
182
206
}
183
207
184
208
pub fn relate < T > (
@@ -223,6 +247,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
223
247
let value = op. relate ( expected, actual) ?;
224
248
Ok ( InferOk { value, obligations : op. into_obligations ( ) } )
225
249
}
250
+
251
+ fn goals_to_obligations (
252
+ & self ,
253
+ goals : Vec < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
254
+ ) -> InferOk < ' tcx , ( ) > {
255
+ InferOk {
256
+ value : ( ) ,
257
+ obligations : goals
258
+ . into_iter ( )
259
+ . map ( |goal| {
260
+ Obligation :: new (
261
+ self . infcx . tcx ,
262
+ self . cause . clone ( ) ,
263
+ goal. param_env ,
264
+ goal. predicate ,
265
+ )
266
+ } )
267
+ . collect ( ) ,
268
+ }
269
+ }
226
270
}
227
271
228
272
impl < ' tcx > ToTrace < ' tcx > for ImplSubject < ' tcx > {
0 commit comments