@@ -8,6 +8,7 @@ use std::assert_matches::assert_matches;
88use rustc_errors:: { Applicability , Diag , EmissionGuarantee } ;
99use rustc_hir as hir;
1010use rustc_hir:: intravisit:: Visitor ;
11+ use rustc_index:: IndexSlice ;
1112use rustc_infer:: infer:: NllRegionVariableOrigin ;
1213use rustc_middle:: middle:: resolve_bound_vars:: ObjectLifetimeDefault ;
1314use rustc_middle:: mir:: {
@@ -17,15 +18,14 @@ use rustc_middle::mir::{
1718use rustc_middle:: ty:: adjustment:: PointerCoercion ;
1819use rustc_middle:: ty:: { self , RegionVid , Ty , TyCtxt } ;
1920use rustc_middle:: util:: CallKind ;
20- use rustc_span:: { DesugaringKind , Span , kw, sym} ;
21+ use rustc_span:: { DesugaringKind , Span , Symbol , kw, sym} ;
2122use rustc_trait_selection:: error_reporting:: traits:: FindExprBySpan ;
2223use tracing:: { debug, instrument} ;
2324
2425use super :: { RegionName , UseSpans , find_use} ;
2526use crate :: borrow_set:: BorrowData ;
26- use crate :: constraints:: OutlivesConstraint ;
2727use crate :: nll:: ConstraintDescription ;
28- use crate :: region_infer:: { BlameConstraint , Cause } ;
28+ use crate :: region_infer:: { BlameConstraint , Cause , ExtraConstraintInfo } ;
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- path : Vec < OutlivesConstraint < ' tcx > > ,
46+ extra_info : Vec < ExtraConstraintInfo > ,
4747 } ,
4848 Unexplained ,
4949}
@@ -63,16 +63,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
6363 }
6464 pub ( crate ) fn add_explanation_to_diagnostic < G : EmissionGuarantee > (
6565 & self ,
66- cx : & MirBorrowckCtxt < ' _ , ' _ , ' tcx > ,
66+ tcx : TyCtxt < ' tcx > ,
67+ body : & Body < ' tcx > ,
68+ local_names : & IndexSlice < Local , Option < Symbol > > ,
6769 err : & mut Diag < ' _ , G > ,
6870 borrow_desc : & str ,
6971 borrow_span : Option < Span > ,
7072 multiple_borrow_span : Option < ( Span , Span ) > ,
7173 ) {
72- let tcx = cx. infcx . tcx ;
73- let body = cx. body ;
74- let local_names = & cx. local_names ;
75-
7674 if let Some ( span) = borrow_span {
7775 let def_id = body. source . def_id ( ) ;
7876 if let Some ( node) = tcx. hir ( ) . get_if_local ( def_id)
@@ -308,7 +306,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
308306 ref region_name,
309307 ref opt_place_desc,
310308 from_closure : _,
311- ref path ,
309+ ref extra_info ,
312310 } => {
313311 region_name. highlight_region_name ( err) ;
314312
@@ -330,8 +328,13 @@ impl<'tcx> BorrowExplanation<'tcx> {
330328 ) ;
331329 } ;
332330
333- cx. add_placeholder_from_predicate_note ( err, & path) ;
334- cx. add_sized_or_copy_bound_info ( err, category, & path) ;
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+ }
335338
336339 if let ConstraintCategory :: Cast {
337340 is_implicit_coercion : true ,
@@ -484,9 +487,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
484487 & self ,
485488 borrow_region : RegionVid ,
486489 outlived_region : RegionVid ,
487- ) -> ( ConstraintCategory < ' tcx > , bool , Span , Option < RegionName > , Vec < OutlivesConstraint < ' tcx > > )
488- {
489- let ( blame_constraint, path) = self . regioncx . best_blame_constraint (
490+ ) -> ( ConstraintCategory < ' tcx > , bool , Span , Option < RegionName > , Vec < ExtraConstraintInfo > ) {
491+ let ( blame_constraint, extra_info) = self . regioncx . best_blame_constraint (
490492 borrow_region,
491493 NllRegionVariableOrigin :: FreeRegion ,
492494 |r| self . regioncx . provides_universal_region ( r, borrow_region, outlived_region) ,
@@ -495,7 +497,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
495497
496498 let outlived_fr_name = self . give_region_a_name ( outlived_region) ;
497499
498- ( category, from_closure, cause. span , outlived_fr_name, path )
500+ ( category, from_closure, cause. span , outlived_fr_name, extra_info )
499501 }
500502
501503 /// Returns structured explanation for *why* the borrow contains the
@@ -594,7 +596,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
594596
595597 None => {
596598 if let Some ( region) = self . to_error_region_vid ( borrow_region_vid) {
597- let ( category, from_closure, span, region_name, path ) =
599+ let ( category, from_closure, span, region_name, extra_info ) =
598600 self . free_region_constraint_info ( borrow_region_vid, region) ;
599601 if let Some ( region_name) = region_name {
600602 let opt_place_desc = self . describe_place ( borrow. borrowed_place . as_ref ( ) ) ;
@@ -604,7 +606,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
604606 span,
605607 region_name,
606608 opt_place_desc,
607- path ,
609+ extra_info ,
608610 }
609611 } else {
610612 debug ! ( "Could not generate a region name" ) ;
0 commit comments