@@ -48,11 +48,6 @@ pub struct At<'a, 'tcx> {
4848 pub param_env : ty:: ParamEnv < ' tcx > ,
4949}
5050
51- pub struct Trace < ' a , ' tcx > {
52- at : At < ' a , ' tcx > ,
53- trace : TypeTrace < ' tcx > ,
54- }
55-
5651impl < ' tcx > InferCtxt < ' tcx > {
5752 #[ inline]
5853 pub fn at < ' a > (
@@ -109,9 +104,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
109104 /// call like `foo(x)`, where `foo: fn(i32)`, you might have
110105 /// `sup(i32, x)`, since the "expected" type is the type that
111106 /// appears in the signature.
112- ///
113- /// See [`At::trace`] and [`Trace::sub`] for a version of
114- /// this method that only requires `T: Relate<'tcx>`
115107 pub fn sup < T > (
116108 self ,
117109 define_opaque_types : DefineOpaqueTypes ,
@@ -121,13 +113,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
121113 where
122114 T : ToTrace < ' tcx > ,
123115 {
124- self . trace ( expected, actual) . sup ( define_opaque_types, expected, actual)
116+ let mut fields = CombineFields :: new (
117+ self . infcx ,
118+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
119+ self . param_env ,
120+ define_opaque_types,
121+ ) ;
122+ fields
123+ . sup ( )
124+ . relate ( expected, actual)
125+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
125126 }
126127
127128 /// Makes `expected <: actual`.
128- ///
129- /// See [`At::trace`] and [`Trace::sub`] for a version of
130- /// this method that only requires `T: Relate<'tcx>`
131129 pub fn sub < T > (
132130 self ,
133131 define_opaque_types : DefineOpaqueTypes ,
@@ -137,13 +135,19 @@ impl<'a, 'tcx> At<'a, 'tcx> {
137135 where
138136 T : ToTrace < ' tcx > ,
139137 {
140- self . trace ( expected, actual) . sub ( define_opaque_types, expected, actual)
138+ let mut fields = CombineFields :: new (
139+ self . infcx ,
140+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
141+ self . param_env ,
142+ define_opaque_types,
143+ ) ;
144+ fields
145+ . sub ( )
146+ . relate ( expected, actual)
147+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
141148 }
142149
143- /// Makes `expected <: actual`.
144- ///
145- /// See [`At::trace`] and [`Trace::eq`] for a version of
146- /// this method that only requires `T: Relate<'tcx>`
150+ /// Makes `expected == actual`.
147151 pub fn eq < T > (
148152 self ,
149153 define_opaque_types : DefineOpaqueTypes ,
@@ -153,7 +157,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
153157 where
154158 T : ToTrace < ' tcx > ,
155159 {
156- self . trace ( expected, actual) . eq ( define_opaque_types, expected, actual)
160+ let mut fields = CombineFields :: new (
161+ self . infcx ,
162+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
163+ self . param_env ,
164+ define_opaque_types,
165+ ) ;
166+ fields
167+ . equate ( StructurallyRelateAliases :: No )
168+ . relate ( expected, actual)
169+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
157170 }
158171
159172 /// Equates `expected` and `found` while structurally relating aliases.
@@ -167,10 +180,17 @@ impl<'a, 'tcx> At<'a, 'tcx> {
167180 where
168181 T : ToTrace < ' tcx > ,
169182 {
170- self . trace ( expected, actual) . eq_structurally_relating_aliases (
171- expected,
172- actual,
173- )
183+ assert ! ( self . infcx. next_trait_solver( ) ) ;
184+ let mut fields = CombineFields :: new (
185+ self . infcx ,
186+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
187+ self . param_env ,
188+ DefineOpaqueTypes :: Yes ,
189+ ) ;
190+ fields
191+ . equate ( StructurallyRelateAliases :: Yes )
192+ . relate ( expected, actual)
193+ . map ( |_| InferOk { value : ( ) , obligations : fields. obligations } )
174194 }
175195
176196 pub fn relate < T > (
@@ -202,9 +222,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
202222 /// this can result in an error (e.g., if asked to compute LUB of
203223 /// u32 and i32), it is meaningful to call one of them the
204224 /// "expected type".
205- ///
206- /// See [`At::trace`] and [`Trace::lub`] for a version of
207- /// this method that only requires `T: Relate<'tcx>`
208225 pub fn lub < T > (
209226 self ,
210227 define_opaque_types : DefineOpaqueTypes ,
@@ -214,15 +231,21 @@ impl<'a, 'tcx> At<'a, 'tcx> {
214231 where
215232 T : ToTrace < ' tcx > ,
216233 {
217- self . trace ( expected, actual) . lub ( define_opaque_types, expected, actual)
234+ let mut fields = CombineFields :: new (
235+ self . infcx ,
236+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
237+ self . param_env ,
238+ define_opaque_types,
239+ ) ;
240+ fields
241+ . lub ( )
242+ . relate ( expected, actual)
243+ . map ( |value| InferOk { value, obligations : fields. obligations } )
218244 }
219245
220246 /// Computes the greatest-lower-bound, or mutual subtype, of two
221247 /// values. As with `lub` order doesn't matter, except for error
222248 /// cases.
223- ///
224- /// See [`At::trace`] and [`Trace::glb`] for a version of
225- /// this method that only requires `T: Relate<'tcx>`
226249 pub fn glb < T > (
227250 self ,
228251 define_opaque_types : DefineOpaqueTypes ,
@@ -232,105 +255,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
232255 where
233256 T : ToTrace < ' tcx > ,
234257 {
235- self . trace ( expected, actual) . glb ( define_opaque_types, expected, actual)
236- }
237-
238- /// Sets the "trace" values that will be used for
239- /// error-reporting, but doesn't actually perform any operation
240- /// yet (this is useful when you want to set the trace using
241- /// distinct values from those you wish to operate upon).
242- pub fn trace < T > ( self , expected : T , actual : T ) -> Trace < ' a , ' tcx >
243- where
244- T : ToTrace < ' tcx > ,
245- {
246- let trace = ToTrace :: to_trace ( self . cause , true , expected, actual) ;
247- Trace { at : self , trace }
248- }
249- }
250-
251- impl < ' a , ' tcx > Trace < ' a , ' tcx > {
252- /// Makes `a <: b`.
253- #[ instrument( skip( self ) , level = "debug" ) ]
254- pub fn sub < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
255- where
256- T : Relate < ' tcx > ,
257- {
258- let Trace { at, trace } = self ;
259- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
260- fields
261- . sub ( )
262- . relate ( a, b)
263- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
264- }
265-
266- /// Makes `a :> b`.
267- #[ instrument( skip( self ) , level = "debug" ) ]
268- pub fn sup < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
269- where
270- T : Relate < ' tcx > ,
271- {
272- let Trace { at, trace } = self ;
273- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
274- fields
275- . sup ( )
276- . relate ( a, b)
277- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
278- }
279-
280- /// Makes `a == b`.
281- #[ instrument( skip( self ) , level = "debug" ) ]
282- pub fn eq < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , ( ) >
283- where
284- T : Relate < ' tcx > ,
285- {
286- let Trace { at, trace } = self ;
287- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
288- fields
289- . equate ( StructurallyRelateAliases :: No )
290- . relate ( a, b)
291- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
292- }
293-
294- /// Equates `a` and `b` while structurally relating aliases. This should only
295- /// be used inside of the next generation trait solver when relating rigid aliases.
296- #[ instrument( skip( self ) , level = "debug" ) ]
297- pub fn eq_structurally_relating_aliases < T > ( self , a : T , b : T ) -> InferResult < ' tcx , ( ) >
298- where
299- T : Relate < ' tcx > ,
300- {
301- let Trace { at, trace } = self ;
302- debug_assert ! ( at. infcx. next_trait_solver( ) ) ;
303- let mut fields = at. infcx . combine_fields ( trace, at. param_env , DefineOpaqueTypes :: Yes ) ;
304- fields
305- . equate ( StructurallyRelateAliases :: Yes )
306- . relate ( a, b)
307- . map ( move |_| InferOk { value : ( ) , obligations : fields. obligations } )
308- }
309-
310- #[ instrument( skip( self ) , level = "debug" ) ]
311- pub fn lub < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , T >
312- where
313- T : Relate < ' tcx > ,
314- {
315- let Trace { at, trace } = self ;
316- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
317- fields
318- . lub ( )
319- . relate ( a, b)
320- . map ( move |t| InferOk { value : t, obligations : fields. obligations } )
321- }
322-
323- #[ instrument( skip( self ) , level = "debug" ) ]
324- pub fn glb < T > ( self , define_opaque_types : DefineOpaqueTypes , a : T , b : T ) -> InferResult < ' tcx , T >
325- where
326- T : Relate < ' tcx > ,
327- {
328- let Trace { at, trace } = self ;
329- let mut fields = at. infcx . combine_fields ( trace, at. param_env , define_opaque_types) ;
258+ let mut fields = CombineFields :: new (
259+ self . infcx ,
260+ ToTrace :: to_trace ( self . cause , true , expected, actual) ,
261+ self . param_env ,
262+ define_opaque_types,
263+ ) ;
330264 fields
331265 . glb ( )
332- . relate ( a , b )
333- . map ( move |t | InferOk { value : t , obligations : fields. obligations } )
266+ . relate ( expected , actual )
267+ . map ( |value | InferOk { value, obligations : fields. obligations } )
334268 }
335269}
336270
0 commit comments