11use rustc_errors:: Diag ;
2+ use rustc_hir:: def_id:: LocalDefId ;
23use rustc_infer:: infer:: canonical:: Canonical ;
34use rustc_infer:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
45use rustc_infer:: infer:: region_constraints:: Constraint ;
@@ -241,7 +242,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
241242 mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
242243 let ocx = ObligationCtxt :: new ( & infcx) ;
243244 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 ( ) )
245246 }
246247}
247248
@@ -287,7 +288,7 @@ where
287288 let ( param_env, value) = key. into_parts ( ) ;
288289 let _ = ocx. normalize ( & cause, param_env, value. value ) ;
289290
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 ( ) )
291292 }
292293}
293294
@@ -318,7 +319,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
318319 mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
319320 let ocx = ObligationCtxt :: new ( & infcx) ;
320321 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 ( ) )
322323 }
323324}
324325
@@ -351,6 +352,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
351352 // our `mbcx` instead.
352353 |vid| mbcx. regioncx . var_infos [ vid] . origin ,
353354 |vid| mbcx. regioncx . var_infos [ vid] . universe ,
355+ mbcx. mir_def_id ( ) ,
354356 )
355357 }
356358}
@@ -360,6 +362,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
360362 ocx : & ObligationCtxt < ' _ , ' tcx > ,
361363 placeholder_region : ty:: Region < ' tcx > ,
362364 error_region : Option < ty:: Region < ' tcx > > ,
365+ generic_param_scope : LocalDefId ,
363366) -> Option < Diag < ' tcx > > {
364367 // We generally shouldn't have errors here because the query was
365368 // already run, but there's no point using `span_delayed_bug`
@@ -373,6 +376,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
373376 & region_constraints,
374377 |vid| ocx. infcx . region_var_origin ( vid) ,
375378 |vid| ocx. infcx . universe_of_region ( ty:: Region :: new_var ( ocx. infcx . tcx , vid) ) ,
379+ generic_param_scope,
376380 )
377381}
378382
@@ -384,6 +388,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
384388 region_constraints : & RegionConstraintData < ' tcx > ,
385389 mut region_var_origin : impl FnMut ( RegionVid ) -> RegionVariableOrigin ,
386390 mut universe_of_region : impl FnMut ( RegionVid ) -> UniverseIndex ,
391+ generic_param_scope : LocalDefId ,
387392) -> Option < Diag < ' tcx > > {
388393 let placeholder_universe = match placeholder_region. kind ( ) {
389394 ty:: RePlaceholder ( p) => p. universe ,
@@ -452,15 +457,18 @@ fn try_extract_error_from_region_constraints<'tcx>(
452457 RegionResolutionError :: ConcreteFailure ( cause. clone ( ) , sub_region, placeholder_region)
453458 }
454459 } ;
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+ } )
466474}
0 commit comments