2727
2828use relate:: lattice:: { LatticeOp , LatticeOpKind } ;
2929use rustc_middle:: ty:: relate:: solver_relating:: RelateExt as NextSolverRelate ;
30- use rustc_middle:: ty:: { Const , TypingMode } ;
30+ use rustc_middle:: ty:: { Const , ParamEnv , TypingMode } ;
3131use rustc_span:: bug;
3232
3333use super :: * ;
@@ -124,6 +124,143 @@ impl<'tcx> InferCtxt<'tcx> {
124124 forked. inner . borrow_mut ( ) . projection_cache ( ) . clear ( ) ;
125125 forked
126126 }
127+
128+ /// Makes `actual <: expected`. For example, if type-checking a
129+ /// call like `foo(x)`, where `foo: fn(i32)`, you might have
130+ /// `sup(i32, x)`, since the "expected" type is the type that
131+ /// appears in the signature.
132+ ///
133+ /// If possible, prefer the wrapper methods on `ObligationCtxt`,
134+ /// `FnCtxt`, or `TypeChecker`.
135+ pub fn sup_raw < T > (
136+ self ,
137+ cause : & ObligationCause < ' tcx > ,
138+ param_env : ParamEnv < ' tcx > ,
139+ define_opaque_types : DefineOpaqueTypes ,
140+ expected : T ,
141+ actual : T ,
142+ ) -> InferResult < ' tcx , ( ) >
143+ where
144+ T : ToTrace < ' tcx > ,
145+ {
146+ self . at ( cause, param_env) . sup ( define_opaque_types, expected, actual)
147+ }
148+
149+ /// Makes `expected <: actual`.
150+ ///
151+ /// If possible, prefer the wrapper methods on `ObligationCtxt`,
152+ /// `FnCtxt`, or `TypeChecker`.
153+ pub fn sub_raw < T > (
154+ self ,
155+ cause : & ObligationCause < ' tcx > ,
156+ param_env : ParamEnv < ' tcx > ,
157+ define_opaque_types : DefineOpaqueTypes ,
158+ expected : T ,
159+ actual : T ,
160+ ) -> InferResult < ' tcx , ( ) >
161+ where
162+ T : ToTrace < ' tcx > ,
163+ {
164+ self . at ( cause, param_env) . sub ( define_opaque_types, expected, actual)
165+ }
166+
167+ /// Makes `expected == actual`.
168+ ///
169+ /// If possible, prefer the wrapper methods on `ObligationCtxt`,
170+ /// `FnCtxt`, or `TypeChecker`.
171+ pub fn eq_raw < T > (
172+ self ,
173+ cause : & ObligationCause < ' tcx > ,
174+ param_env : ParamEnv < ' tcx > ,
175+ define_opaque_types : DefineOpaqueTypes ,
176+ expected : T ,
177+ actual : T ,
178+ ) -> InferResult < ' tcx , ( ) >
179+ where
180+ T : ToTrace < ' tcx > ,
181+ {
182+ self . eq_trace_raw (
183+ cause,
184+ param_env,
185+ define_opaque_types,
186+ ToTrace :: to_trace ( cause, expected, actual) ,
187+ expected,
188+ actual,
189+ )
190+ }
191+
192+ /// Makes `expected == actual`.
193+ ///
194+ /// If possible, prefer the wrapper methods on `ObligationCtxt`,
195+ /// `FnCtxt`, or `TypeChecker`.
196+ pub fn eq_trace_raw < T > (
197+ self ,
198+ cause : & ObligationCause < ' tcx > ,
199+ param_env : ParamEnv < ' tcx > ,
200+ define_opaque_types : DefineOpaqueTypes ,
201+ trace : TypeTrace < ' tcx > ,
202+ expected : T ,
203+ actual : T ,
204+ ) -> InferResult < ' tcx , ( ) >
205+ where
206+ T : Relate < TyCtxt < ' tcx > > ,
207+ {
208+ self . at ( cause, param_env) . eq_trace ( define_opaque_types, trace, expected, actual)
209+ }
210+
211+ /// If possible, prefer the wrapper methods on `ObligationCtxt`,
212+ /// `FnCtxt`, or `TypeChecker`.
213+ pub fn relate_raw < T > (
214+ self ,
215+ cause : & ObligationCause < ' tcx > ,
216+ param_env : ParamEnv < ' tcx > ,
217+ define_opaque_types : DefineOpaqueTypes ,
218+ expected : T ,
219+ variance : ty:: Variance ,
220+ actual : T ,
221+ ) -> InferResult < ' tcx , ( ) >
222+ where
223+ T : ToTrace < ' tcx > ,
224+ {
225+ self . at ( cause, param_env) . relate ( define_opaque_types, expected, variance, actual)
226+ }
227+
228+ /// Computes the least-upper-bound, or mutual supertype, of two
229+ /// values. The order of the arguments doesn't matter, but since
230+ /// this can result in an error (e.g., if asked to compute LUB of
231+ /// u32 and i32), it is meaningful to call one of them the
232+ /// "expected type".
233+ ///
234+ /// If possible, prefer the wrapper methods on `ObligationCtxt`,
235+ /// `FnCtxt`, or `TypeChecker`.
236+ pub fn lub_raw < T > (
237+ self ,
238+ cause : & ObligationCause < ' tcx > ,
239+ param_env : ParamEnv < ' tcx > ,
240+ expected : T ,
241+ actual : T ,
242+ ) -> InferResult < ' tcx , T >
243+ where
244+ T : ToTrace < ' tcx > ,
245+ {
246+ self . at ( cause, param_env) . lub ( expected, actual)
247+ }
248+
249+ pub fn goals_to_obligations (
250+ & self ,
251+ cause : & ObligationCause < ' tcx > ,
252+ goals : Vec < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
253+ ) -> InferOk < ' tcx , ( ) > {
254+ InferOk {
255+ value : ( ) ,
256+ obligations : goals
257+ . into_iter ( )
258+ . map ( |goal| {
259+ Obligation :: new ( self . tcx , cause. clone ( ) , goal. param_env , goal. predicate )
260+ } )
261+ . collect ( ) ,
262+ }
263+ }
127264}
128265
129266pub trait ToTrace < ' tcx > : Relate < TyCtxt < ' tcx > > + Copy {
@@ -135,6 +272,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
135272 /// call like `foo(x)`, where `foo: fn(i32)`, you might have
136273 /// `sup(i32, x)`, since the "expected" type is the type that
137274 /// appears in the signature.
275+ ///
276+ /// FIXME: To be removed in favor of the [`InferCtxt::sup_raw`] method instead.
138277 pub fn sup < T > (
139278 self ,
140279 define_opaque_types : DefineOpaqueTypes ,
@@ -168,6 +307,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
168307 }
169308
170309 /// Makes `expected <: actual`.
310+ ///
311+ /// FIXME: To be removed in favor of the [`InferCtxt::sub_raw`] method instead.
171312 pub fn sub < T > (
172313 self ,
173314 define_opaque_types : DefineOpaqueTypes ,
@@ -201,6 +342,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
201342 }
202343
203344 /// Makes `expected == actual`.
345+ ///
346+ /// FIXME: To be removed in favor of the [`InferCtxt::eq_raw`] method instead.
204347 pub fn eq < T > (
205348 self ,
206349 define_opaque_types : DefineOpaqueTypes ,
@@ -219,6 +362,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
219362 }
220363
221364 /// Makes `expected == actual`.
365+ ///
366+ /// FIXME: To be removed in favor of the [`InferCtxt::eq_trace_raw`] method instead.
222367 pub fn eq_trace < T > (
223368 self ,
224369 define_opaque_types : DefineOpaqueTypes ,
@@ -252,6 +397,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
252397 }
253398 }
254399
400+ /// FIXME: To be removed in favor of the [`InferCtxt::relate_raw`] method instead.
255401 pub fn relate < T > (
256402 self ,
257403 define_opaque_types : DefineOpaqueTypes ,
@@ -281,6 +427,8 @@ impl<'a, 'tcx> At<'a, 'tcx> {
281427 /// this can result in an error (e.g., if asked to compute LUB of
282428 /// u32 and i32), it is meaningful to call one of them the
283429 /// "expected type".
430+ ///
431+ /// FIXME: To be removed in favor of the [`InferCtxt::lub_raw`] method instead.
284432 pub fn lub < T > ( self , expected : T , actual : T ) -> InferResult < ' tcx , T >
285433 where
286434 T : ToTrace < ' tcx > ,
@@ -295,6 +443,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
295443 Ok ( InferOk { value, obligations : op. into_obligations ( ) } )
296444 }
297445
446+ /// FIXME: To be removed in favor of the [`InferCtxt::goals_to_obligations`] method instead.
298447 fn goals_to_obligations (
299448 & self ,
300449 goals : Vec < Goal < ' tcx , ty:: Predicate < ' tcx > > > ,
0 commit comments