@@ -34,7 +34,13 @@ 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_REGION : Cell <Option <( ty:: BoundRegion , usize ) >> = Cell :: new( None )
38
44
}
39
45
40
46
macro_rules! gen_display_debug_body {
@@ -564,12 +570,34 @@ pub fn parameterized<F: fmt::Write>(f: &mut F,
564
570
PrintContext :: new ( ) . parameterized ( f, substs, did, projections)
565
571
}
566
572
567
- fn get_highlight_region ( ) -> Option < ( RegionVid , usize ) > {
568
- HIGHLIGHT_REGION . with ( |hr| hr. get ( ) )
573
+ fn get_highlight_region_for_regionvid ( ) -> Option < ( RegionVid , usize ) > {
574
+ HIGHLIGHT_REGION_FOR_REGIONVID . with ( |hr| hr. get ( ) )
569
575
}
570
576
571
- pub fn with_highlight_region < R > ( r : RegionVid , counter : usize , op : impl FnOnce ( ) -> R ) -> R {
572
- HIGHLIGHT_REGION . with ( |hr| {
577
+ pub fn with_highlight_region_for_regionvid < R > (
578
+ r : RegionVid ,
579
+ counter : usize ,
580
+ op : impl FnOnce ( ) -> R
581
+ ) -> R {
582
+ HIGHLIGHT_REGION_FOR_REGIONVID . with ( |hr| {
583
+ assert_eq ! ( hr. get( ) , None ) ;
584
+ hr. set ( Some ( ( r, counter) ) ) ;
585
+ let r = op ( ) ;
586
+ hr. set ( None ) ;
587
+ r
588
+ } )
589
+ }
590
+
591
+ fn get_highlight_region_for_region ( ) -> Option < ( ty:: BoundRegion , usize ) > {
592
+ HIGHLIGHT_REGION_FOR_REGION . with ( |hr| hr. get ( ) )
593
+ }
594
+
595
+ pub fn with_highlight_region_for_region < R > (
596
+ r : ty:: BoundRegion ,
597
+ counter : usize ,
598
+ op : impl Fn ( ) -> R
599
+ ) -> R {
600
+ HIGHLIGHT_REGION_FOR_REGION . with ( |hr| {
573
601
assert_eq ! ( hr. get( ) , None ) ;
574
602
hr. set ( Some ( ( r, counter) ) ) ;
575
603
let r = op ( ) ;
@@ -726,6 +754,15 @@ define_print! {
726
754
return self . print_debug( f, cx) ;
727
755
}
728
756
757
+ if let Some ( ( region, counter) ) = get_highlight_region_for_region( ) {
758
+ if * self == region {
759
+ return match * self {
760
+ BrNamed ( _, name) => write!( f, "{}" , name) ,
761
+ BrAnon ( _) | BrFresh ( _) | BrEnv => write!( f, "'{}" , counter)
762
+ } ;
763
+ }
764
+ }
765
+
729
766
match * self {
730
767
BrNamed ( _, name) => write!( f, "{}" , name) ,
731
768
BrAnon ( _) | BrFresh ( _) | BrEnv => Ok ( ( ) )
@@ -748,7 +785,7 @@ define_print! {
748
785
define_print ! {
749
786
( ) ty:: RegionKind , ( self , f, cx) {
750
787
display {
751
- if cx. is_verbose || get_highlight_region ( ) . is_some( ) {
788
+ if cx. is_verbose || get_highlight_region_for_regionvid ( ) . is_some( ) {
752
789
return self . print_debug( f, cx) ;
753
790
}
754
791
@@ -923,7 +960,7 @@ impl fmt::Debug for ty::FloatVid {
923
960
924
961
impl fmt:: Debug for ty:: RegionVid {
925
962
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
926
- if let Some ( ( region, counter) ) = get_highlight_region ( ) {
963
+ if let Some ( ( region, counter) ) = get_highlight_region_for_regionvid ( ) {
927
964
debug ! ( "RegionVid.fmt: region={:?} self={:?} counter={:?}" , region, self , counter) ;
928
965
return if * self == region {
929
966
write ! ( f, "'{:?}" , counter)
0 commit comments