@@ -8,7 +8,6 @@ use std::assert_matches::assert_matches;
88use rustc_errors:: { Applicability , Diag } ;
99use rustc_hir as hir;
1010use rustc_hir:: intravisit:: Visitor ;
11- use rustc_index:: IndexSlice ;
1211use rustc_infer:: infer:: NllRegionVariableOrigin ;
1312use rustc_middle:: middle:: resolve_bound_vars:: ObjectLifetimeDefault ;
1413use rustc_middle:: mir:: {
@@ -18,14 +17,15 @@ use rustc_middle::mir::{
1817use rustc_middle:: ty:: adjustment:: PointerCoercion ;
1918use rustc_middle:: ty:: { self , RegionVid , Ty , TyCtxt } ;
2019use rustc_middle:: util:: CallKind ;
21- use rustc_span:: { DesugaringKind , Span , Symbol , kw, sym} ;
20+ use rustc_span:: { DesugaringKind , Span , kw, sym} ;
2221use rustc_trait_selection:: error_reporting:: traits:: FindExprBySpan ;
2322use tracing:: { debug, instrument} ;
2423
2524use super :: { RegionName , UseSpans , find_use} ;
2625use crate :: borrow_set:: BorrowData ;
26+ use crate :: constraints:: OutlivesConstraint ;
2727use crate :: nll:: ConstraintDescription ;
28- use crate :: region_infer:: { BlameConstraint , Cause , ExtraConstraintInfo } ;
28+ use crate :: region_infer:: { BlameConstraint , Cause } ;
2929use crate :: { MirBorrowckCtxt , WriteKind } ;
3030
3131#[ derive( Debug ) ]
@@ -43,7 +43,7 @@ pub(crate) enum BorrowExplanation<'tcx> {
4343 span : Span ,
4444 region_name : RegionName ,
4545 opt_place_desc : Option < String > ,
46- extra_info : Vec < ExtraConstraintInfo > ,
46+ path : Vec < OutlivesConstraint < ' tcx > > ,
4747 } ,
4848 Unexplained ,
4949}
@@ -63,14 +63,16 @@ impl<'tcx> BorrowExplanation<'tcx> {
6363 }
6464 pub ( crate ) fn add_explanation_to_diagnostic (
6565 & self ,
66- tcx : TyCtxt < ' tcx > ,
67- body : & Body < ' tcx > ,
68- local_names : & IndexSlice < Local , Option < Symbol > > ,
66+ cx : & MirBorrowckCtxt < ' _ , ' _ , ' tcx > ,
6967 err : & mut Diag < ' _ > ,
7068 borrow_desc : & str ,
7169 borrow_span : Option < Span > ,
7270 multiple_borrow_span : Option < ( Span , Span ) > ,
7371 ) {
72+ let tcx = cx. infcx . tcx ;
73+ let body = cx. body ;
74+ let local_names = & cx. local_names ;
75+
7476 if let Some ( span) = borrow_span {
7577 let def_id = body. source . def_id ( ) ;
7678 if let Some ( node) = tcx. hir ( ) . get_if_local ( def_id)
@@ -306,7 +308,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
306308 ref region_name,
307309 ref opt_place_desc,
308310 from_closure : _,
309- ref extra_info ,
311+ ref path ,
310312 } => {
311313 region_name. highlight_region_name ( err) ;
312314
@@ -328,13 +330,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
328330 ) ;
329331 } ;
330332
331- for extra in extra_info {
332- match extra {
333- ExtraConstraintInfo :: PlaceholderFromPredicate ( span) => {
334- err. span_note ( * span, "due to current limitations in the borrow checker, this implies a `'static` lifetime" ) ;
335- }
336- }
337- }
333+ cx. add_placeholder_from_predicate_note ( err, & path) ;
334+ cx. add_sized_or_copy_bound_info ( err, category, & path) ;
338335
339336 if let ConstraintCategory :: Cast {
340337 is_implicit_coercion : true ,
@@ -487,8 +484,9 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
487484 & self ,
488485 borrow_region : RegionVid ,
489486 outlived_region : RegionVid ,
490- ) -> ( ConstraintCategory < ' tcx > , bool , Span , Option < RegionName > , Vec < ExtraConstraintInfo > ) {
491- let ( blame_constraint, extra_info) = self . regioncx . best_blame_constraint (
487+ ) -> ( ConstraintCategory < ' tcx > , bool , Span , Option < RegionName > , Vec < OutlivesConstraint < ' tcx > > )
488+ {
489+ let ( blame_constraint, path) = self . regioncx . best_blame_constraint (
492490 borrow_region,
493491 NllRegionVariableOrigin :: FreeRegion ,
494492 |r| self . regioncx . provides_universal_region ( r, borrow_region, outlived_region) ,
@@ -497,7 +495,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
497495
498496 let outlived_fr_name = self . give_region_a_name ( outlived_region) ;
499497
500- ( category, from_closure, cause. span , outlived_fr_name, extra_info )
498+ ( category, from_closure, cause. span , outlived_fr_name, path )
501499 }
502500
503501 /// Returns structured explanation for *why* the borrow contains the
@@ -596,7 +594,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
596594
597595 None => {
598596 if let Some ( region) = self . to_error_region_vid ( borrow_region_vid) {
599- let ( category, from_closure, span, region_name, extra_info ) =
597+ let ( category, from_closure, span, region_name, path ) =
600598 self . free_region_constraint_info ( borrow_region_vid, region) ;
601599 if let Some ( region_name) = region_name {
602600 let opt_place_desc = self . describe_place ( borrow. borrowed_place . as_ref ( ) ) ;
@@ -606,7 +604,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
606604 span,
607605 region_name,
608606 opt_place_desc,
609- extra_info ,
607+ path ,
610608 }
611609 } else {
612610 debug ! ( "Could not generate a region name" ) ;
0 commit comments