@@ -119,17 +119,6 @@ impl RegionHighlightMode {
119
119
Self :: highlighting_region ( & ty:: ReVar ( vid) , number, op)
120
120
}
121
121
122
- /// Returns true if any placeholders are highlighted.
123
- fn any_region_vids_highlighted ( & self ) -> bool {
124
- Self :: get ( )
125
- . highlight_regions
126
- . iter ( )
127
- . any ( |h| match h {
128
- Some ( ( ty:: ReVar ( _) , _) ) => true ,
129
- _ => false ,
130
- } )
131
- }
132
-
133
122
/// Returns `Some(n)` with the number to use for the given region,
134
123
/// if any.
135
124
fn region_highlighted ( & self , region : ty:: Region < ' _ > ) -> Option < usize > {
@@ -163,17 +152,6 @@ impl RegionHighlightMode {
163
152
)
164
153
}
165
154
166
- /// Returns true if any placeholders are highlighted.
167
- pub fn any_placeholders_highlighted ( & self ) -> bool {
168
- Self :: get ( )
169
- . highlight_regions
170
- . iter ( )
171
- . any ( |h| match h {
172
- Some ( ( ty:: RePlaceholder ( _) , _) ) => true ,
173
- _ => false ,
174
- } )
175
- }
176
-
177
155
/// Returns `Some(N)` if the placeholder `p` is highlighted to print as `'N`.
178
156
pub fn placeholder_highlight ( & self , p : ty:: PlaceholderRegion ) -> Option < usize > {
179
157
self . region_highlighted ( & ty:: RePlaceholder ( p) )
@@ -420,7 +398,7 @@ impl PrintCx<'a, 'gcx, 'tcx> {
420
398
if self . is_verbose {
421
399
write ! ( f, "{:?}" , region) ?;
422
400
} else {
423
- let s = region. to_string ( ) ;
401
+ let s = region. print_display_to_string ( self ) ;
424
402
if s. is_empty ( ) {
425
403
// This happens when the value of the region
426
404
// parameter is not easily serialized. This may be
@@ -714,19 +692,20 @@ define_print! {
714
692
return self . print_debug( f, cx) ;
715
693
}
716
694
717
- if let Some ( ( region, counter) ) = RegionHighlightMode :: get( ) . highlight_bound_region {
718
- if * self == region {
719
- return match * self {
720
- BrNamed ( _, name) => write!( f, "{}" , name) ,
721
- BrAnon ( _) | BrFresh ( _) | BrEnv => write!( f, "'{}" , counter)
722
- } ;
695
+ if let BrNamed ( _, name) = * self {
696
+ if name != "" && name != "'_" {
697
+ return write!( f, "{}" , name) ;
723
698
}
724
699
}
725
700
726
- match * self {
727
- BrNamed ( _, name) => write!( f, "{}" , name) ,
728
- BrAnon ( _) | BrFresh ( _) | BrEnv => Ok ( ( ) )
701
+ let highlight = RegionHighlightMode :: get( ) ;
702
+ if let Some ( ( region, counter) ) = highlight. highlight_bound_region {
703
+ if * self == region {
704
+ return write!( f, "'{}" , counter) ;
705
+ }
729
706
}
707
+
708
+ Ok ( ( ) )
730
709
}
731
710
debug {
732
711
return match * self {
@@ -751,12 +730,10 @@ define_print! {
751
730
752
731
let highlight = RegionHighlightMode :: get( ) ;
753
732
if let Some ( counter) = highlight. placeholder_highlight( * self ) {
754
- write!( f, "'{}" , counter)
755
- } else if highlight. any_placeholders_highlighted( ) {
756
- write!( f, "'_" )
757
- } else {
758
- write!( f, "{}" , self . name)
733
+ return write!( f, "'{}" , counter) ;
759
734
}
735
+
736
+ write!( f, "{}" , self . name)
760
737
}
761
738
}
762
739
}
@@ -779,7 +756,11 @@ define_print! {
779
756
// `explain_region()` or `note_and_explain_region()`.
780
757
match * self {
781
758
ty:: ReEarlyBound ( ref data) => {
782
- write!( f, "{}" , data. name)
759
+ if data. name != "'_" {
760
+ write!( f, "{}" , data. name)
761
+ } else {
762
+ Ok ( ( ) )
763
+ }
783
764
}
784
765
ty:: ReLateBound ( _, br) |
785
766
ty:: ReFree ( ty:: FreeRegion { bound_region: br, .. } ) => {
@@ -806,14 +787,11 @@ define_print! {
806
787
) ,
807
788
}
808
789
}
790
+ ty:: ReVar ( region_vid) if cx. identify_regions => {
791
+ write!( f, "{:?}" , region_vid)
792
+ }
809
793
ty:: ReVar ( region_vid) => {
810
- if RegionHighlightMode :: get( ) . any_region_vids_highlighted( ) {
811
- write!( f, "{:?}" , region_vid)
812
- } else if cx. identify_regions {
813
- write!( f, "'{}rv" , region_vid. index( ) )
814
- } else {
815
- Ok ( ( ) )
816
- }
794
+ write!( f, "{}" , region_vid)
817
795
}
818
796
ty:: ReScope ( _) |
819
797
ty:: ReErased => Ok ( ( ) ) ,
@@ -926,32 +904,46 @@ impl fmt::Debug for ty::FloatVid {
926
904
}
927
905
}
928
906
929
- impl fmt:: Debug for ty:: RegionVid {
930
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
931
- if let Some ( counter) = RegionHighlightMode :: get ( ) . region_highlighted ( & ty:: ReVar ( * self ) ) {
932
- return write ! ( f, "'{:?}" , counter) ;
933
- } else if RegionHighlightMode :: get ( ) . any_region_vids_highlighted ( ) {
934
- return write ! ( f, "'_" ) ;
907
+ define_print ! {
908
+ ( ) ty:: RegionVid , ( self , f, cx) {
909
+ display {
910
+ if cx. is_verbose {
911
+ return self . print_debug( f, cx) ;
912
+ }
913
+
914
+ let highlight = RegionHighlightMode :: get( ) ;
915
+ if let Some ( counter) = highlight. region_highlighted( & ty:: ReVar ( * self ) ) {
916
+ return write!( f, "'{:?}" , counter) ;
917
+ }
918
+
919
+ Ok ( ( ) )
935
920
}
921
+ debug {
922
+ // HACK(eddyb) this is duplicated from `display` printing,
923
+ // to keep NLL borrowck working even with `-Zverbose`.
924
+ let highlight = RegionHighlightMode :: get( ) ;
925
+ if let Some ( counter) = highlight. region_highlighted( & ty:: ReVar ( * self ) ) {
926
+ return write!( f, "'{:?}" , counter) ;
927
+ }
936
928
937
- write ! ( f, "'_#{}r" , self . index( ) )
929
+ write!( f, "'_#{}r" , self . index( ) )
930
+ }
938
931
}
939
932
}
940
933
941
934
define_print ! {
942
935
( ) ty:: InferTy , ( self , f, cx) {
943
936
display {
944
937
if cx. is_verbose {
945
- print!( f, cx, print_debug( self ) )
946
- } else {
947
- match * self {
948
- ty:: TyVar ( _) => write!( f, "_" ) ,
949
- ty:: IntVar ( _) => write!( f, "{}" , "{integer}" ) ,
950
- ty:: FloatVar ( _) => write!( f, "{}" , "{float}" ) ,
951
- ty:: FreshTy ( v) => write!( f, "FreshTy({})" , v) ,
952
- ty:: FreshIntTy ( v) => write!( f, "FreshIntTy({})" , v) ,
953
- ty:: FreshFloatTy ( v) => write!( f, "FreshFloatTy({})" , v)
954
- }
938
+ return self . print_debug( f, cx) ;
939
+ }
940
+ match * self {
941
+ ty:: TyVar ( _) => write!( f, "_" ) ,
942
+ ty:: IntVar ( _) => write!( f, "{}" , "{integer}" ) ,
943
+ ty:: FloatVar ( _) => write!( f, "{}" , "{float}" ) ,
944
+ ty:: FreshTy ( v) => write!( f, "FreshTy({})" , v) ,
945
+ ty:: FreshIntTy ( v) => write!( f, "FreshIntTy({})" , v) ,
946
+ ty:: FreshFloatTy ( v) => write!( f, "FreshFloatTy({})" , v)
955
947
}
956
948
}
957
949
debug {
@@ -1049,12 +1041,9 @@ define_print! {
1049
1041
}
1050
1042
Ref ( r, ty, mutbl) => {
1051
1043
write!( f, "&" ) ?;
1052
- let s = r. print_to_string( cx) ;
1053
- if s != "'_" {
1054
- write!( f, "{}" , s) ?;
1055
- if !s. is_empty( ) {
1056
- write!( f, " " ) ?;
1057
- }
1044
+ let s = r. print_display_to_string( cx) ;
1045
+ if !s. is_empty( ) {
1046
+ write!( f, "{} " , s) ?;
1058
1047
}
1059
1048
ty:: TypeAndMut { ty, mutbl } . print( f, cx)
1060
1049
}
@@ -1100,7 +1089,7 @@ define_print! {
1100
1089
}
1101
1090
Adt ( def, substs) => cx. parameterized( f, def. did, substs, iter:: empty( ) ) ,
1102
1091
Dynamic ( data, r) => {
1103
- let r = r. print_to_string ( cx) ;
1092
+ let r = r. print_display_to_string ( cx) ;
1104
1093
if !r. is_empty( ) {
1105
1094
write!( f, "(" ) ?;
1106
1095
}
0 commit comments