1
1
use rustc_errors:: Diag ;
2
+ use rustc_hir:: def_id:: LocalDefId ;
2
3
use rustc_infer:: infer:: canonical:: Canonical ;
3
4
use rustc_infer:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
4
5
use rustc_infer:: infer:: region_constraints:: Constraint ;
@@ -241,7 +242,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
241
242
mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
242
243
let ocx = ObligationCtxt :: new ( & infcx) ;
243
244
type_op_prove_predicate_with_cause ( & ocx, key, cause) ;
244
- try_extract_error_from_fulfill_cx ( & ocx, placeholder_region, error_region)
245
+ try_extract_error_from_fulfill_cx ( & ocx, placeholder_region, error_region, mbcx . mir_def_id ( ) )
245
246
}
246
247
}
247
248
@@ -287,7 +288,7 @@ where
287
288
let ( param_env, value) = key. into_parts ( ) ;
288
289
let _ = ocx. normalize ( & cause, param_env, value. value ) ;
289
290
290
- try_extract_error_from_fulfill_cx ( & ocx, placeholder_region, error_region)
291
+ try_extract_error_from_fulfill_cx ( & ocx, placeholder_region, error_region, mbcx . mir_def_id ( ) )
291
292
}
292
293
}
293
294
@@ -318,7 +319,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
318
319
mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
319
320
let ocx = ObligationCtxt :: new ( & infcx) ;
320
321
type_op_ascribe_user_type_with_span ( & ocx, key, Some ( cause. span ) ) . ok ( ) ?;
321
- try_extract_error_from_fulfill_cx ( & ocx, placeholder_region, error_region)
322
+ try_extract_error_from_fulfill_cx ( & ocx, placeholder_region, error_region, mbcx . mir_def_id ( ) )
322
323
}
323
324
}
324
325
@@ -351,6 +352,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
351
352
// our `mbcx` instead.
352
353
|vid| mbcx. regioncx . var_infos [ vid] . origin ,
353
354
|vid| mbcx. regioncx . var_infos [ vid] . universe ,
355
+ mbcx. mir_def_id ( ) ,
354
356
)
355
357
}
356
358
}
@@ -360,6 +362,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
360
362
ocx : & ObligationCtxt < ' _ , ' tcx > ,
361
363
placeholder_region : ty:: Region < ' tcx > ,
362
364
error_region : Option < ty:: Region < ' tcx > > ,
365
+ generic_param_scope : LocalDefId ,
363
366
) -> Option < Diag < ' tcx > > {
364
367
// We generally shouldn't have errors here because the query was
365
368
// already run, but there's no point using `span_delayed_bug`
@@ -373,6 +376,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
373
376
& region_constraints,
374
377
|vid| ocx. infcx . region_var_origin ( vid) ,
375
378
|vid| ocx. infcx . universe_of_region ( ty:: Region :: new_var ( ocx. infcx . tcx , vid) ) ,
379
+ generic_param_scope,
376
380
)
377
381
}
378
382
@@ -384,6 +388,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
384
388
region_constraints : & RegionConstraintData < ' tcx > ,
385
389
mut region_var_origin : impl FnMut ( RegionVid ) -> RegionVariableOrigin ,
386
390
mut universe_of_region : impl FnMut ( RegionVid ) -> UniverseIndex ,
391
+ generic_param_scope : LocalDefId ,
387
392
) -> Option < Diag < ' tcx > > {
388
393
let placeholder_universe = match placeholder_region. kind ( ) {
389
394
ty:: RePlaceholder ( p) => p. universe ,
@@ -452,15 +457,18 @@ fn try_extract_error_from_region_constraints<'tcx>(
452
457
RegionResolutionError :: ConcreteFailure ( cause. clone ( ) , sub_region, placeholder_region)
453
458
}
454
459
} ;
455
- NiceRegionError :: new ( & infcx. err_ctxt ( ) , error) . try_report_from_nll ( ) . or_else ( || {
456
- if let SubregionOrigin :: Subtype ( trace) = cause {
457
- Some (
458
- infcx
459
- . err_ctxt ( )
460
- . report_and_explain_type_error ( * trace, TypeError :: RegionsPlaceholderMismatch ) ,
461
- )
462
- } else {
463
- None
464
- }
465
- } )
460
+ NiceRegionError :: new ( & infcx. err_ctxt ( ) , error, generic_param_scope)
461
+ . try_report_from_nll ( )
462
+ . or_else ( || {
463
+ if let SubregionOrigin :: Subtype ( trace) = cause {
464
+ Some (
465
+ infcx. err_ctxt ( ) . report_and_explain_type_error (
466
+ * trace,
467
+ TypeError :: RegionsPlaceholderMismatch ,
468
+ ) ,
469
+ )
470
+ } else {
471
+ None
472
+ }
473
+ } )
466
474
}
0 commit comments