@@ -34,7 +34,14 @@ use hir;
3434thread_local ! {
3535 /// Mechanism for highlighting of specific regions for display in NLL region inference errors.
3636 /// Contains region to highlight and counter for number to use when highlighting.
37- static HIGHLIGHT_REGION : Cell <Option <( RegionVid , usize ) >> = Cell :: new( None )
37+ static HIGHLIGHT_REGION_FOR_REGIONVID : Cell <Option <( RegionVid , usize ) >> = Cell :: new( None )
38+ }
39+
40+ thread_local ! {
41+ /// Mechanism for highlighting of specific regions for display in NLL's 'borrow does not live
42+ /// long enough' errors. Contains a region to highlight and a counter to use.
43+ static HIGHLIGHT_REGION_FOR_BOUND_REGION : Cell <Option <( ty:: BoundRegion , usize ) >> =
44+ Cell :: new( None )
3845}
3946
4047macro_rules! gen_display_debug_body {
@@ -564,12 +571,34 @@ pub fn parameterized<F: fmt::Write>(f: &mut F,
564571 PrintContext :: new ( ) . parameterized ( f, substs, did, projections)
565572}
566573
567- fn get_highlight_region ( ) -> Option < ( RegionVid , usize ) > {
568- HIGHLIGHT_REGION . with ( |hr| hr. get ( ) )
574+ fn get_highlight_region_for_regionvid ( ) -> Option < ( RegionVid , usize ) > {
575+ HIGHLIGHT_REGION_FOR_REGIONVID . with ( |hr| hr. get ( ) )
569576}
570577
571- pub fn with_highlight_region < R > ( r : RegionVid , counter : usize , op : impl FnOnce ( ) -> R ) -> R {
572- HIGHLIGHT_REGION . with ( |hr| {
578+ pub fn with_highlight_region_for_regionvid < R > (
579+ r : RegionVid ,
580+ counter : usize ,
581+ op : impl FnOnce ( ) -> R
582+ ) -> R {
583+ HIGHLIGHT_REGION_FOR_REGIONVID . with ( |hr| {
584+ assert_eq ! ( hr. get( ) , None ) ;
585+ hr. set ( Some ( ( r, counter) ) ) ;
586+ let r = op ( ) ;
587+ hr. set ( None ) ;
588+ r
589+ } )
590+ }
591+
592+ fn get_highlight_region_for_bound_region ( ) -> Option < ( ty:: BoundRegion , usize ) > {
593+ HIGHLIGHT_REGION_FOR_BOUND_REGION . with ( |hr| hr. get ( ) )
594+ }
595+
596+ pub fn with_highlight_region_for_bound_region < R > (
597+ r : ty:: BoundRegion ,
598+ counter : usize ,
599+ op : impl Fn ( ) -> R
600+ ) -> R {
601+ HIGHLIGHT_REGION_FOR_BOUND_REGION . with ( |hr| {
573602 assert_eq ! ( hr. get( ) , None ) ;
574603 hr. set ( Some ( ( r, counter) ) ) ;
575604 let r = op ( ) ;
@@ -726,6 +755,15 @@ define_print! {
726755 return self . print_debug( f, cx) ;
727756 }
728757
758+ if let Some ( ( region, counter) ) = get_highlight_region_for_bound_region( ) {
759+ if * self == region {
760+ return match * self {
761+ BrNamed ( _, name) => write!( f, "{}" , name) ,
762+ BrAnon ( _) | BrFresh ( _) | BrEnv => write!( f, "'{}" , counter)
763+ } ;
764+ }
765+ }
766+
729767 match * self {
730768 BrNamed ( _, name) => write!( f, "{}" , name) ,
731769 BrAnon ( _) | BrFresh ( _) | BrEnv => Ok ( ( ) )
@@ -748,7 +786,7 @@ define_print! {
748786define_print ! {
749787 ( ) ty:: RegionKind , ( self , f, cx) {
750788 display {
751- if cx. is_verbose || get_highlight_region ( ) . is_some( ) {
789+ if cx. is_verbose || get_highlight_region_for_regionvid ( ) . is_some( ) {
752790 return self . print_debug( f, cx) ;
753791 }
754792
@@ -923,7 +961,7 @@ impl fmt::Debug for ty::FloatVid {
923961
924962impl fmt:: Debug for ty:: RegionVid {
925963 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
926- if let Some ( ( region, counter) ) = get_highlight_region ( ) {
964+ if let Some ( ( region, counter) ) = get_highlight_region_for_regionvid ( ) {
927965 debug ! ( "RegionVid.fmt: region={:?} self={:?} counter={:?}" , region, self , counter) ;
928966 return if * self == region {
929967 write ! ( f, "'{:?}" , counter)
0 commit comments