@@ -222,14 +222,10 @@ pub trait PrettyPrinter:
222222 false
223223 }
224224
225- // HACK(eddyb) Trying to print a lifetime might not print anything, which
226- // may need special handling in the caller (of `ty::RegionKind::print`).
227- // To avoid printing to a temporary string (which isn't even supported),
228- // the `print_region_outputs_anything` method can instead be used to
229- // determine this, ahead of time.
230- //
231- // NB: this must be kept in sync with the implementation of `print_region`.
232- fn print_region_outputs_anything (
225+ /// Return `true` if the region should be printed in
226+ /// optional positions, e.g. `&'a T` or `dyn Tr + 'b`.
227+ /// This is typically the case for all non-`'_` regions.
228+ fn region_should_not_be_omitted (
233229 self : & PrintCx < ' _ , ' _ , ' _ , Self > ,
234230 region : ty:: Region < ' _ > ,
235231 ) -> bool ;
@@ -497,7 +493,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
497493 match substs[ param. index as usize ] . unpack ( ) {
498494 UnpackedKind :: Lifetime ( r) => {
499495 self . always_print_region_in_paths ( r) ||
500- self . print_region_outputs_anything ( r)
496+ self . region_should_not_be_omitted ( r)
501497 }
502498 _ => false ,
503499 }
@@ -535,19 +531,6 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
535531 for arg in arg0. into_iter ( ) . chain ( args) {
536532 maybe_comma ( & mut cx) ?;
537533
538- if let UnpackedKind :: Lifetime ( region) = arg. unpack ( ) {
539- if !cx. print_region_outputs_anything ( region) {
540- // This happens when the value of the region
541- // parameter is not easily serialized. This may be
542- // because the user omitted it in the first place,
543- // or because it refers to some block in the code,
544- // etc. I'm not sure how best to serialize this.
545- p ! ( write( "'_" ) ) ;
546-
547- continue ;
548- }
549- }
550-
551534 p ! ( print( arg) ) ;
552535 }
553536
@@ -822,7 +805,7 @@ impl<F: fmt::Write> PrettyPrinter for FmtPrinter<F> {
822805 * region != ty:: ReErased
823806 }
824807
825- fn print_region_outputs_anything (
808+ fn region_should_not_be_omitted (
826809 self : & PrintCx < ' _ , ' _ , ' _ , Self > ,
827810 region : ty:: Region < ' _ > ,
828811 ) -> bool {
@@ -902,8 +885,9 @@ impl<F: fmt::Write> FmtPrinter<F> {
902885 // `explain_region()` or `note_and_explain_region()`.
903886 match * region {
904887 ty:: ReEarlyBound ( ref data) => {
905- if data. name != "'_ " {
888+ if data. name != "" {
906889 p ! ( write( "{}" , data. name) ) ;
890+ return self . ok ( ) ;
907891 }
908892 }
909893 ty:: ReLateBound ( _, br) |
@@ -919,6 +903,7 @@ impl<F: fmt::Write> FmtPrinter<F> {
919903 if let Some ( ( region, counter) ) = highlight. highlight_bound_region {
920904 if br == region {
921905 p ! ( write( "'{}" , counter) ) ;
906+ return self . ok ( ) ;
922907 }
923908 }
924909 }
@@ -938,20 +923,33 @@ impl<F: fmt::Write> FmtPrinter<F> {
938923 first_statement_index. index( )
939924 ) ) ,
940925 }
926+ return self . ok ( ) ;
941927 }
942928 ty:: ReVar ( region_vid) if identify_regions => {
943929 p ! ( write( "{:?}" , region_vid) ) ;
930+ return self . ok ( ) ;
944931 }
945932 ty:: ReVar ( _) => { }
946933 ty:: ReScope ( _) |
947934 ty:: ReErased => { }
948- ty:: ReStatic => p ! ( write( "'static" ) ) ,
949- ty:: ReEmpty => p ! ( write( "'<empty>" ) ) ,
935+ ty:: ReStatic => {
936+ p ! ( write( "'static" ) ) ;
937+ return self . ok ( ) ;
938+ }
939+ ty:: ReEmpty => {
940+ p ! ( write( "'<empty>" ) ) ;
941+ return self . ok ( ) ;
942+ }
950943
951944 // The user should never encounter these in unsubstituted form.
952- ty:: ReClosureBound ( vid) => p ! ( write( "{:?}" , vid) ) ,
945+ ty:: ReClosureBound ( vid) => {
946+ p ! ( write( "{:?}" , vid) ) ;
947+ return self . ok ( ) ;
948+ }
953949 }
954950
951+ p ! ( write( "'_" ) ) ;
952+
955953 self . ok ( )
956954 }
957955}
@@ -978,7 +976,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
978976 }
979977 ty:: Ref ( r, ty, mutbl) => {
980978 p ! ( write( "&" ) ) ;
981- if self . print_region_outputs_anything ( r) {
979+ if self . region_should_not_be_omitted ( r) {
982980 p ! ( print( r) , write( " " ) ) ;
983981 }
984982 p ! ( print( ty:: TypeAndMut { ty, mutbl } ) )
@@ -1027,7 +1025,7 @@ impl<'gcx, 'tcx, P: PrettyPrinter> PrintCx<'_, 'gcx, 'tcx, P> {
10271025 nest ! ( |cx| cx. print_def_path( def. did, Some ( substs) , iter:: empty( ) ) ) ;
10281026 }
10291027 ty:: Dynamic ( data, r) => {
1030- let print_r = self . print_region_outputs_anything ( r) ;
1028+ let print_r = self . region_should_not_be_omitted ( r) ;
10311029 if print_r {
10321030 p ! ( write( "(" ) ) ;
10331031 }
0 commit comments