@@ -34,7 +34,14 @@ use hir;
34
34
thread_local ! {
35
35
/// Mechanism for highlighting of specific regions for display in NLL region inference errors.
36
36
/// 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 )
38
45
}
39
46
40
47
macro_rules! gen_display_debug_body {
@@ -564,12 +571,34 @@ pub fn parameterized<F: fmt::Write>(f: &mut F,
564
571
PrintContext :: new ( ) . parameterized ( f, substs, did, projections)
565
572
}
566
573
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 ( ) )
569
576
}
570
577
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| {
573
602
assert_eq ! ( hr. get( ) , None ) ;
574
603
hr. set ( Some ( ( r, counter) ) ) ;
575
604
let r = op ( ) ;
@@ -726,6 +755,15 @@ define_print! {
726
755
return self . print_debug( f, cx) ;
727
756
}
728
757
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
+
729
767
match * self {
730
768
BrNamed ( _, name) => write!( f, "{}" , name) ,
731
769
BrAnon ( _) | BrFresh ( _) | BrEnv => Ok ( ( ) )
@@ -748,7 +786,7 @@ define_print! {
748
786
define_print ! {
749
787
( ) ty:: RegionKind , ( self , f, cx) {
750
788
display {
751
- if cx. is_verbose || get_highlight_region ( ) . is_some( ) {
789
+ if cx. is_verbose || get_highlight_region_for_regionvid ( ) . is_some( ) {
752
790
return self . print_debug( f, cx) ;
753
791
}
754
792
@@ -923,7 +961,7 @@ impl fmt::Debug for ty::FloatVid {
923
961
924
962
impl fmt:: Debug for ty:: RegionVid {
925
963
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 ( ) {
927
965
debug ! ( "RegionVid.fmt: region={:?} self={:?} counter={:?}" , region, self , counter) ;
928
966
return if * self == region {
929
967
write ! ( f, "'{:?}" , counter)
0 commit comments