@@ -831,14 +831,27 @@ pub trait PrettyPrinter<'tcx>:
831
831
Ok ( self )
832
832
}
833
833
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 > {
835
839
define_scoped_cx ! ( self ) ;
836
840
837
841
if self . tcx ( ) . sess . verbose ( ) {
838
842
p ! ( write( "Const({:?}: {:?})" , ct. val, ct. ty) ) ;
839
843
return Ok ( self ) ;
840
844
}
841
845
846
+ macro_rules! print_underscore {
847
+ ( ) => { {
848
+ p!( write( "_" ) ) ;
849
+ if print_ty {
850
+ p!( write( ": " ) , print( ct. ty) ) ;
851
+ }
852
+ } } ;
853
+ }
854
+
842
855
match ( ct. val , & ct. ty . kind ) {
843
856
( _, ty:: FnDef ( did, substs) ) => p ! ( print_value_path( * did, substs) ) ,
844
857
( ty:: ConstKind :: Unevaluated ( did, substs, promoted) , _) => {
@@ -857,22 +870,27 @@ pub trait PrettyPrinter<'tcx>:
857
870
{
858
871
p ! ( write( "{}" , snip) )
859
872
} else {
860
- p ! ( write ( "_: " ) , print ( ct . ty ) )
873
+ print_underscore ! ( )
861
874
}
862
875
} else {
863
- p ! ( write ( "_: " ) , print ( ct . ty ) )
876
+ print_underscore ! ( )
864
877
}
865
878
}
866
879
}
867
880
}
868
881
}
869
- ( ty:: ConstKind :: Infer ( ..) , _) => p ! ( write ( "_: " ) , print ( ct . ty ) ) ,
882
+ ( ty:: ConstKind :: Infer ( ..) , _) => print_underscore ! ( ) ,
870
883
( 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
+ }
872
887
873
888
_ => {
874
889
// 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
+ }
876
894
}
877
895
} ;
878
896
Ok ( self )
@@ -882,6 +900,7 @@ pub trait PrettyPrinter<'tcx>:
882
900
mut self ,
883
901
ct : ConstValue < ' tcx > ,
884
902
ty : Ty < ' tcx > ,
903
+ print_ty : bool ,
885
904
) -> Result < Self :: Const , Self :: Error > {
886
905
define_scoped_cx ! ( self ) ;
887
906
@@ -988,7 +1007,10 @@ pub trait PrettyPrinter<'tcx>:
988
1007
} ;
989
1008
if !printed {
990
1009
// fallback
991
- p ! ( write( "{:?} : " , ct) , print( ty) )
1010
+ p ! ( write( "{:?}" , ct) ) ;
1011
+ if print_ty {
1012
+ p ! ( write( " : " ) , print( ty) ) ;
1013
+ }
992
1014
}
993
1015
}
994
1016
} ;
@@ -1162,7 +1184,7 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
1162
1184
}
1163
1185
1164
1186
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 )
1166
1188
}
1167
1189
1168
1190
fn path_crate ( mut self , cnum : CrateNum ) -> Result < Self :: Path , Self :: Error > {
0 commit comments