@@ -831,14 +831,27 @@ pub trait PrettyPrinter<'tcx>:
831831 Ok ( self )
832832 }
833833
834- fn pretty_print_const ( mut self , ct : & ' tcx ty:: Const < ' tcx > ) -> Result < Self :: Const , Self :: Error > {
834+ fn pretty_print_const (
835+ mut self ,
836+ ct : & ' tcx ty:: Const < ' tcx > ,
837+ print_ty : bool ,
838+ ) -> Result < Self :: Const , Self :: Error > {
835839 define_scoped_cx ! ( self ) ;
836840
837841 if self . tcx ( ) . sess . verbose ( ) {
838842 p ! ( write( "Const({:?}: {:?})" , ct. val, ct. ty) ) ;
839843 return Ok ( self ) ;
840844 }
841845
846+ macro_rules! print_underscore {
847+ ( ) => { {
848+ p!( write( "_" ) ) ;
849+ if print_ty {
850+ p!( write( ": " ) , print( ct. ty) ) ;
851+ }
852+ } } ;
853+ }
854+
842855 match ( ct. val , & ct. ty . kind ) {
843856 ( _, ty:: FnDef ( did, substs) ) => p ! ( print_value_path( * did, substs) ) ,
844857 ( ty:: ConstKind :: Unevaluated ( did, substs, promoted) , _) => {
@@ -857,22 +870,27 @@ pub trait PrettyPrinter<'tcx>:
857870 {
858871 p ! ( write( "{}" , snip) )
859872 } else {
860- p ! ( write ( "_: " ) , print ( ct . ty ) )
873+ print_underscore ! ( )
861874 }
862875 } else {
863- p ! ( write ( "_: " ) , print ( ct . ty ) )
876+ print_underscore ! ( )
864877 }
865878 }
866879 }
867880 }
868881 }
869- ( ty:: ConstKind :: Infer ( ..) , _) => p ! ( write ( "_: " ) , print ( ct . ty ) ) ,
882+ ( ty:: ConstKind :: Infer ( ..) , _) => print_underscore ! ( ) ,
870883 ( ty:: ConstKind :: Param ( ParamConst { name, .. } ) , _) => p ! ( write( "{}" , name) ) ,
871- ( ty:: ConstKind :: Value ( value) , _) => return self . pretty_print_const_value ( value, ct. ty ) ,
884+ ( ty:: ConstKind :: Value ( value) , _) => {
885+ return self . pretty_print_const_value ( value, ct. ty , print_ty) ;
886+ }
872887
873888 _ => {
874889 // fallback
875- p ! ( write( "{:?} : " , ct. val) , print( ct. ty) )
890+ p ! ( write( "{:?}" , ct. val) ) ;
891+ if print_ty {
892+ p ! ( write( " : " ) , print( ct. ty) ) ;
893+ }
876894 }
877895 } ;
878896 Ok ( self )
@@ -882,6 +900,7 @@ pub trait PrettyPrinter<'tcx>:
882900 mut self ,
883901 ct : ConstValue < ' tcx > ,
884902 ty : Ty < ' tcx > ,
903+ print_ty : bool ,
885904 ) -> Result < Self :: Const , Self :: Error > {
886905 define_scoped_cx ! ( self ) ;
887906
@@ -988,7 +1007,10 @@ pub trait PrettyPrinter<'tcx>:
9881007 } ;
9891008 if !printed {
9901009 // fallback
991- p ! ( write( "{:?} : " , ct) , print( ty) )
1010+ p ! ( write( "{:?}" , ct) ) ;
1011+ if print_ty {
1012+ p ! ( write( " : " ) , print( ty) ) ;
1013+ }
9921014 }
9931015 }
9941016 } ;
@@ -1162,7 +1184,7 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
11621184 }
11631185
11641186 fn print_const ( self , ct : & ' tcx ty:: Const < ' tcx > ) -> Result < Self :: Const , Self :: Error > {
1165- self . pretty_print_const ( ct)
1187+ self . pretty_print_const ( ct, true )
11661188 }
11671189
11681190 fn path_crate ( mut self , cnum : CrateNum ) -> Result < Self :: Path , Self :: Error > {
0 commit comments