2727
2828use relate:: lattice:: { LatticeOp , LatticeOpKind } ;
2929use rustc_middle:: bug;
30+ use rustc_middle:: ty:: relate:: solver_relating:: RelateExt as NextSolverRelate ;
3031use rustc_middle:: ty:: { Const , ImplSubject } ;
3132
3233use super :: * ;
3334use crate :: infer:: relate:: type_relating:: TypeRelating ;
3435use crate :: infer:: relate:: { Relate , TypeRelation } ;
36+ use crate :: traits:: Obligation ;
37+ use crate :: traits:: solve:: Goal ;
3538
3639/// Whether we should define opaque types or just treat them opaquely.
3740///
@@ -109,15 +112,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109112 where
110113 T : ToTrace < ' tcx > ,
111114 {
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+ }
121135 }
122136
123137 /// Makes `expected <: actual`.
@@ -130,15 +144,20 @@ impl<'a, 'tcx> At<'a, 'tcx> {
130144 where
131145 T : ToTrace < ' tcx > ,
132146 {
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+ }
142161 }
143162
144163 /// Makes `expected == actual`.
@@ -170,15 +189,20 @@ impl<'a, 'tcx> At<'a, 'tcx> {
170189 where
171190 T : Relate < TyCtxt < ' tcx > > ,
172191 {
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+ }
182206 }
183207
184208 pub fn relate < T > (
@@ -223,6 +247,26 @@ impl<'a, 'tcx> At<'a, 'tcx> {
223247 let value = op. relate ( expected, actual) ?;
224248 Ok ( InferOk { value, obligations : op. into_obligations ( ) } )
225249 }
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+ }
226270}
227271
228272impl < ' tcx > ToTrace < ' tcx > for ImplSubject < ' tcx > {
0 commit comments