@@ -210,19 +210,16 @@ pub trait PrettyPrinter<'tcx>:
210
210
Ok ( self )
211
211
}
212
212
213
- /// Prints `{...}` around what `f` and optionally `t` print
213
+ /// Prints `{...}` around what `f` ( and optionally `t`) print
214
214
fn type_ascribed_value (
215
215
mut self ,
216
216
f : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
217
217
t : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
218
- print_ty : bool ,
219
218
) -> Result < Self :: Const , Self :: Error > {
220
219
self . write_str ( "{" ) ?;
221
220
self = f ( self ) ?;
222
- if print_ty {
223
- self . write_str ( ": " ) ?;
224
- self = t ( self ) ?;
225
- }
221
+ self . write_str ( ": " ) ?;
222
+ self = t ( self ) ?;
226
223
self . write_str ( "}" ) ?;
227
224
Ok ( self )
228
225
}
@@ -1003,14 +1000,15 @@ pub trait PrettyPrinter<'tcx>:
1003
1000
( Scalar :: Raw { size : 0 , .. } , _) => p ! ( print( ty) ) ,
1004
1001
// Nontrivial types with scalar bit representation
1005
1002
( Scalar :: Raw { data, size } , _) => {
1006
- self = self . type_ascribed_value (
1007
- |mut this| {
1008
- write ! ( this, "0x{:01$x}" , data, size as usize * 2 ) ?;
1009
- Ok ( this)
1010
- } ,
1011
- |this| this. print_type ( ty) ,
1012
- print_ty,
1013
- ) ?
1003
+ let print = |mut this : Self | {
1004
+ write ! ( this, "0x{:01$x}" , data, size as usize * 2 ) ?;
1005
+ Ok ( this)
1006
+ } ;
1007
+ self = if print_ty {
1008
+ self . type_ascribed_value ( print, |this| this. print_type ( ty) ) ?
1009
+ } else {
1010
+ print ( self ) ?
1011
+ } ;
1014
1012
}
1015
1013
// Any pointer values not covered by a branch above
1016
1014
( Scalar :: Ptr ( p) , _) => {
@@ -1023,19 +1021,23 @@ pub trait PrettyPrinter<'tcx>:
1023
1021
/// This is overridden for MIR printing because we only want to hide alloc ids from users, not
1024
1022
/// from MIR where it is actually useful.
1025
1023
fn pretty_print_const_pointer (
1026
- self ,
1024
+ mut self ,
1027
1025
_: Pointer ,
1028
1026
ty : Ty < ' tcx > ,
1029
1027
print_ty : bool ,
1030
1028
) -> Result < Self :: Const , Self :: Error > {
1031
- self . type_ascribed_value (
1032
- |mut this| {
1033
- this. write_str ( "pointer" ) ?;
1034
- Ok ( this)
1035
- } ,
1036
- |this| this. print_type ( ty) ,
1037
- print_ty,
1038
- )
1029
+ if print_ty {
1030
+ self . type_ascribed_value (
1031
+ |mut this| {
1032
+ this. write_str ( "&_" ) ?;
1033
+ Ok ( this)
1034
+ } ,
1035
+ |this| this. print_type ( ty) ,
1036
+ )
1037
+ } else {
1038
+ self . write_str ( "&_" ) ?;
1039
+ Ok ( self )
1040
+ }
1039
1041
}
1040
1042
1041
1043
fn pretty_print_byte_str ( mut self , byte_str : & ' tcx [ u8 ] ) -> Result < Self :: Const , Self :: Error > {
@@ -1430,16 +1432,13 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
1430
1432
mut self ,
1431
1433
f : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
1432
1434
t : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
1433
- print_ty : bool ,
1434
1435
) -> Result < Self :: Const , Self :: Error > {
1435
1436
self . write_str ( "{" ) ?;
1436
1437
self = f ( self ) ?;
1437
- if print_ty {
1438
- self . write_str ( ": " ) ?;
1439
- let was_in_value = std:: mem:: replace ( & mut self . in_value , false ) ;
1440
- self = t ( self ) ?;
1441
- self . in_value = was_in_value;
1442
- }
1438
+ self . write_str ( ": " ) ?;
1439
+ let was_in_value = std:: mem:: replace ( & mut self . in_value , false ) ;
1440
+ self = t ( self ) ?;
1441
+ self . in_value = was_in_value;
1443
1442
self . write_str ( "}" ) ?;
1444
1443
Ok ( self )
1445
1444
}
@@ -1507,19 +1506,20 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
1507
1506
ty : Ty < ' tcx > ,
1508
1507
print_ty : bool ,
1509
1508
) -> Result < Self :: Const , Self :: Error > {
1510
- self . type_ascribed_value (
1511
- |mut this| {
1512
- define_scoped_cx ! ( this) ;
1513
- if this. print_alloc_ids {
1514
- p ! ( write( "{:?}" , p) ) ;
1515
- } else {
1516
- p ! ( write( "pointer" ) ) ;
1517
- }
1518
- Ok ( this)
1519
- } ,
1520
- |this| this. print_type ( ty) ,
1521
- print_ty,
1522
- )
1509
+ let print = |mut this : Self | {
1510
+ define_scoped_cx ! ( this) ;
1511
+ if this. print_alloc_ids {
1512
+ p ! ( write( "{:?}" , p) ) ;
1513
+ } else {
1514
+ p ! ( write( "&_" ) ) ;
1515
+ }
1516
+ Ok ( this)
1517
+ } ;
1518
+ if print_ty {
1519
+ self . type_ascribed_value ( print, |this| this. print_type ( ty) )
1520
+ } else {
1521
+ print ( self )
1522
+ }
1523
1523
}
1524
1524
}
1525
1525
0 commit comments