@@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
9
9
use rustc_span:: Span ;
10
10
use rustc_trait_selection:: traits:: query:: type_op;
11
11
use 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 } ;
13
13
14
14
use std:: fmt;
15
15
use std:: rc:: Rc ;
@@ -45,21 +45,20 @@ impl UniverseInfo<'tcx> {
45
45
mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
46
46
placeholder : ty:: PlaceholderRegion ,
47
47
error_element : RegionElement ,
48
- span : Span ,
48
+ cause : ObligationCause < ' tcx > ,
49
49
) {
50
50
match self . 0 {
51
51
UniverseInfoInner :: RelateTys { expected, found } => {
52
- let body_id = mbcx. infcx . tcx . hir ( ) . local_def_id_to_hir_id ( mbcx. mir_def_id ( ) ) ;
53
52
let err = mbcx. infcx . report_mismatched_types (
54
- & ObligationCause :: misc ( span , body_id ) ,
53
+ & cause ,
55
54
expected,
56
55
found,
57
56
TypeError :: RegionsPlaceholderMismatch ,
58
57
) ;
59
58
err. buffer ( & mut mbcx. errors_buffer ) ;
60
59
}
61
60
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 ) ;
63
62
}
64
63
UniverseInfoInner :: Other => {
65
64
// FIXME: This error message isn't great, but it doesn't show
@@ -68,7 +67,7 @@ impl UniverseInfo<'tcx> {
68
67
mbcx. infcx
69
68
. tcx
70
69
. sess
71
- . struct_span_err ( span, "higher-ranked subtype error" )
70
+ . struct_span_err ( cause . span , "higher-ranked subtype error" )
72
71
. buffer ( & mut mbcx. errors_buffer ) ;
73
72
}
74
73
}
@@ -130,7 +129,7 @@ trait TypeOpInfo<'tcx> {
130
129
fn nice_error (
131
130
& self ,
132
131
tcx : TyCtxt < ' tcx > ,
133
- span : Span ,
132
+ cause : ObligationCause < ' tcx > ,
134
133
placeholder_region : ty:: Region < ' tcx > ,
135
134
error_region : Option < ty:: Region < ' tcx > > ,
136
135
) -> Option < DiagnosticBuilder < ' tcx > > ;
@@ -140,7 +139,7 @@ trait TypeOpInfo<'tcx> {
140
139
mbcx : & mut MirBorrowckCtxt < ' _ , ' tcx > ,
141
140
placeholder : ty:: PlaceholderRegion ,
142
141
error_element : RegionElement ,
143
- span : Span ,
142
+ cause : ObligationCause < ' tcx > ,
144
143
) {
145
144
let tcx = mbcx. infcx . tcx ;
146
145
let base_universe = self . base_universe ( ) ;
@@ -150,7 +149,7 @@ trait TypeOpInfo<'tcx> {
150
149
{
151
150
adjusted
152
151
} else {
153
- self . fallback_error ( tcx, span) . buffer ( & mut mbcx. errors_buffer ) ;
152
+ self . fallback_error ( tcx, cause . span ) . buffer ( & mut mbcx. errors_buffer ) ;
154
153
return ;
155
154
} ;
156
155
@@ -175,7 +174,8 @@ trait TypeOpInfo<'tcx> {
175
174
176
175
debug ! ( ?placeholder_region) ;
177
176
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) ;
179
179
180
180
if let Some ( nice_error) = nice_error {
181
181
nice_error. buffer ( & mut mbcx. errors_buffer ) ;
@@ -205,15 +205,24 @@ impl TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
205
205
fn nice_error (
206
206
& self ,
207
207
tcx : TyCtxt < ' tcx > ,
208
- span : Span ,
208
+ cause : ObligationCause < ' tcx > ,
209
209
placeholder_region : ty:: Region < ' tcx > ,
210
210
error_region : Option < ty:: Region < ' tcx > > ,
211
211
) -> 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
+ )
217
226
}
218
227
}
219
228
@@ -239,32 +248,41 @@ where
239
248
fn nice_error (
240
249
& self ,
241
250
tcx : TyCtxt < ' tcx > ,
242
- span : Span ,
251
+ cause : ObligationCause < ' tcx > ,
243
252
placeholder_region : ty:: Region < ' tcx > ,
244
253
error_region : Option < ty:: Region < ' tcx > > ,
245
254
) -> 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
+ )
268
286
}
269
287
}
270
288
@@ -287,15 +305,25 @@ impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
287
305
fn nice_error (
288
306
& self ,
289
307
tcx : TyCtxt < ' tcx > ,
290
- span : Span ,
308
+ cause : ObligationCause < ' tcx > ,
291
309
placeholder_region : ty:: Region < ' tcx > ,
292
310
error_region : Option < ty:: Region < ' tcx > > ,
293
311
) -> 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
+ )
299
327
}
300
328
}
301
329
0 commit comments