@@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
99use rustc_span:: Span ;
1010use rustc_trait_selection:: traits:: query:: type_op;
1111use rustc_trait_selection:: traits:: { SelectionContext , TraitEngineExt as _} ;
12- use rustc_traits:: { type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span } ;
12+ use rustc_traits:: { type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause } ;
1313
1414use std:: fmt;
1515use std:: rc:: Rc ;
@@ -45,21 +45,20 @@ impl UniverseInfo<'tcx> {
4545 mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
4646 placeholder : ty:: PlaceholderRegion ,
4747 error_element : RegionElement ,
48- span : Span ,
48+ cause : ObligationCause < ' tcx > ,
4949 ) {
5050 match self . 0 {
5151 UniverseInfoInner :: RelateTys { expected, found } => {
52- let body_id = mbcx. infcx . tcx . hir ( ) . local_def_id_to_hir_id ( mbcx. mir_def_id ( ) ) ;
5352 let err = mbcx. infcx . report_mismatched_types (
54- & ObligationCause :: misc ( span , body_id ) ,
53+ & cause ,
5554 expected,
5655 found,
5756 TypeError :: RegionsPlaceholderMismatch ,
5857 ) ;
5958 err. buffer ( & mut mbcx. errors_buffer ) ;
6059 }
6160 UniverseInfoInner :: TypeOp ( ref type_op_info) => {
62- type_op_info. report_error ( mbcx, placeholder, error_element, span ) ;
61+ type_op_info. report_error ( mbcx, placeholder, error_element, cause ) ;
6362 }
6463 UniverseInfoInner :: Other => {
6564 // FIXME: This error message isn't great, but it doesn't show
@@ -68,7 +67,7 @@ impl UniverseInfo<'tcx> {
6867 mbcx. infcx
6968 . tcx
7069 . sess
71- . struct_span_err ( span, "higher-ranked subtype error" )
70+ . struct_span_err ( cause . span , "higher-ranked subtype error" )
7271 . buffer ( & mut mbcx. errors_buffer ) ;
7372 }
7473 }
@@ -130,7 +129,7 @@ trait TypeOpInfo<'tcx> {
130129 fn nice_error (
131130 & self ,
132131 tcx : TyCtxt < ' tcx > ,
133- span : Span ,
132+ cause : ObligationCause < ' tcx > ,
134133 placeholder_region : ty:: Region < ' tcx > ,
135134 error_region : Option < ty:: Region < ' tcx > > ,
136135 ) -> Option < DiagnosticBuilder < ' tcx > > ;
@@ -140,7 +139,7 @@ trait TypeOpInfo<'tcx> {
140139 mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
141140 placeholder : ty:: PlaceholderRegion ,
142141 error_element : RegionElement ,
143- span : Span ,
142+ cause : ObligationCause < ' tcx > ,
144143 ) {
145144 let tcx = mbcx. infcx . tcx ;
146145 let base_universe = self . base_universe ( ) ;
@@ -150,7 +149,7 @@ trait TypeOpInfo<'tcx> {
150149 {
151150 adjusted
152151 } else {
153- self . fallback_error ( tcx, span) . buffer ( & mut mbcx. errors_buffer ) ;
152+ self . fallback_error ( tcx, cause . span ) . buffer ( & mut mbcx. errors_buffer ) ;
154153 return ;
155154 } ;
156155
@@ -175,7 +174,8 @@ trait TypeOpInfo<'tcx> {
175174
176175 debug ! ( ?placeholder_region) ;
177176
178- let nice_error = self . nice_error ( tcx, span, placeholder_region, error_region) ;
177+ let span = cause. span ;
178+ let nice_error = self . nice_error ( tcx, cause, placeholder_region, error_region) ;
179179
180180 if let Some ( nice_error) = nice_error {
181181 nice_error. buffer ( & mut mbcx. errors_buffer ) ;
@@ -205,15 +205,24 @@ impl TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
205205 fn nice_error (
206206 & self ,
207207 tcx : TyCtxt < ' tcx > ,
208- span : Span ,
208+ cause : ObligationCause < ' tcx > ,
209209 placeholder_region : ty:: Region < ' tcx > ,
210210 error_region : Option < ty:: Region < ' tcx > > ,
211211 ) -> Option < DiagnosticBuilder < ' tcx > > {
212- tcx. infer_ctxt ( ) . enter_with_canonical ( span, & self . canonical_query , |ref infcx, key, _| {
213- let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
214- type_op_prove_predicate_with_span ( infcx, & mut * fulfill_cx, key, Some ( span) ) ;
215- try_extract_error_from_fulfill_cx ( fulfill_cx, infcx, placeholder_region, error_region)
216- } )
212+ tcx. infer_ctxt ( ) . enter_with_canonical (
213+ cause. span ,
214+ & self . canonical_query ,
215+ |ref infcx, key, _| {
216+ let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
217+ type_op_prove_predicate_with_cause ( infcx, & mut * fulfill_cx, key, cause) ;
218+ try_extract_error_from_fulfill_cx (
219+ fulfill_cx,
220+ infcx,
221+ placeholder_region,
222+ error_region,
223+ )
224+ } ,
225+ )
217226 }
218227}
219228
@@ -239,32 +248,41 @@ where
239248 fn nice_error (
240249 & self ,
241250 tcx : TyCtxt < ' tcx > ,
242- span : Span ,
251+ cause : ObligationCause < ' tcx > ,
243252 placeholder_region : ty:: Region < ' tcx > ,
244253 error_region : Option < ty:: Region < ' tcx > > ,
245254 ) -> Option < DiagnosticBuilder < ' tcx > > {
246- tcx. infer_ctxt ( ) . enter_with_canonical ( span, & self . canonical_query , |ref infcx, key, _| {
247- let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
248-
249- let mut selcx = SelectionContext :: new ( infcx) ;
250-
251- // FIXME(lqd): Unify and de-duplicate the following with the actual
252- // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
253- // `ObligationCause`. The normalization results are currently different between
254- // `AtExt::normalize` used in the query and `normalize` called below: the former fails
255- // to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
256- // after #85499 lands to see if its fixes have erased this difference.
257- let ( param_env, value) = key. into_parts ( ) ;
258- let Normalized { value : _, obligations } = rustc_trait_selection:: traits:: normalize (
259- & mut selcx,
260- param_env,
261- ObligationCause :: dummy_with_span ( span) ,
262- value. value ,
263- ) ;
264- fulfill_cx. register_predicate_obligations ( infcx, obligations) ;
265-
266- try_extract_error_from_fulfill_cx ( fulfill_cx, infcx, placeholder_region, error_region)
267- } )
255+ tcx. infer_ctxt ( ) . enter_with_canonical (
256+ cause. span ,
257+ & self . canonical_query ,
258+ |ref infcx, key, _| {
259+ let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
260+
261+ let mut selcx = SelectionContext :: new ( infcx) ;
262+
263+ // FIXME(lqd): Unify and de-duplicate the following with the actual
264+ // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
265+ // `ObligationCause`. The normalization results are currently different between
266+ // `AtExt::normalize` used in the query and `normalize` called below: the former fails
267+ // to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check
268+ // after #85499 lands to see if its fixes have erased this difference.
269+ let ( param_env, value) = key. into_parts ( ) ;
270+ let Normalized { value : _, obligations } = rustc_trait_selection:: traits:: normalize (
271+ & mut selcx,
272+ param_env,
273+ cause,
274+ value. value ,
275+ ) ;
276+ fulfill_cx. register_predicate_obligations ( infcx, obligations) ;
277+
278+ try_extract_error_from_fulfill_cx (
279+ fulfill_cx,
280+ infcx,
281+ placeholder_region,
282+ error_region,
283+ )
284+ } ,
285+ )
268286 }
269287}
270288
@@ -287,15 +305,25 @@ impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
287305 fn nice_error (
288306 & self ,
289307 tcx : TyCtxt < ' tcx > ,
290- span : Span ,
308+ cause : ObligationCause < ' tcx > ,
291309 placeholder_region : ty:: Region < ' tcx > ,
292310 error_region : Option < ty:: Region < ' tcx > > ,
293311 ) -> Option < DiagnosticBuilder < ' tcx > > {
294- tcx. infer_ctxt ( ) . enter_with_canonical ( span, & self . canonical_query , |ref infcx, key, _| {
295- let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
296- type_op_ascribe_user_type_with_span ( infcx, & mut * fulfill_cx, key, Some ( span) ) . ok ( ) ?;
297- try_extract_error_from_fulfill_cx ( fulfill_cx, infcx, placeholder_region, error_region)
298- } )
312+ tcx. infer_ctxt ( ) . enter_with_canonical (
313+ cause. span ,
314+ & self . canonical_query ,
315+ |ref infcx, key, _| {
316+ let mut fulfill_cx = <dyn TraitEngine < ' _ > >:: new ( tcx) ;
317+ type_op_ascribe_user_type_with_span ( infcx, & mut * fulfill_cx, key, Some ( cause. span ) )
318+ . ok ( ) ?;
319+ try_extract_error_from_fulfill_cx (
320+ fulfill_cx,
321+ infcx,
322+ placeholder_region,
323+ error_region,
324+ )
325+ } ,
326+ )
299327 }
300328}
301329
0 commit comments