@@ -210,6 +210,23 @@ pub trait PrettyPrinter<'tcx>:
210
210
Ok ( self )
211
211
}
212
212
213
+ /// Prints `{...}` around what `f` and optionally `t` print
214
+ fn type_ascribed_value (
215
+ mut self ,
216
+ f : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
217
+ t : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
218
+ print_ty : bool ,
219
+ ) -> Result < Self :: Const , Self :: Error > {
220
+ self . write_str ( "{" ) ?;
221
+ self = f ( self ) ?;
222
+ if print_ty {
223
+ self . write_str ( ": " ) ?;
224
+ self = t ( self ) ?;
225
+ }
226
+ self . write_str ( "}" ) ?;
227
+ Ok ( self )
228
+ }
229
+
213
230
/// Prints `<...>` around what `f` prints.
214
231
fn generic_delimiters (
215
232
self ,
@@ -457,22 +474,6 @@ pub trait PrettyPrinter<'tcx>:
457
474
} )
458
475
}
459
476
460
- fn print_type_ascribed (
461
- mut self ,
462
- f : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
463
- ty : Ty < ' tcx > ,
464
- print_ty : bool ,
465
- ) -> Result < Self :: Const , Self :: Error > {
466
- self . write_str ( "{" ) ?;
467
- self = f ( self ) ?;
468
- if print_ty {
469
- self . write_str ( ": " ) ?;
470
- self = self . print_type ( ty) ?;
471
- }
472
- self . write_str ( "}" ) ?;
473
- Ok ( self )
474
- }
475
-
476
477
fn pretty_print_type ( mut self , ty : Ty < ' tcx > ) -> Result < Self :: Type , Self :: Error > {
477
478
define_scoped_cx ! ( self ) ;
478
479
@@ -1002,12 +1003,12 @@ pub trait PrettyPrinter<'tcx>:
1002
1003
( Scalar :: Raw { size : 0 , .. } , _) => p ! ( print( ty) ) ,
1003
1004
// Nontrivial types with scalar bit representation
1004
1005
( Scalar :: Raw { data, size } , _) => {
1005
- self = self . print_type_ascribed (
1006
+ self = self . type_ascribed_value (
1006
1007
|mut this| {
1007
1008
write ! ( this, "0x{:01$x}" , data, size as usize * 2 ) ?;
1008
1009
Ok ( this)
1009
1010
} ,
1010
- ty ,
1011
+ |this| this . print_type ( ty ) ,
1011
1012
print_ty,
1012
1013
) ?
1013
1014
}
@@ -1027,12 +1028,12 @@ pub trait PrettyPrinter<'tcx>:
1027
1028
ty : Ty < ' tcx > ,
1028
1029
print_ty : bool ,
1029
1030
) -> Result < Self :: Const , Self :: Error > {
1030
- self . print_type_ascribed (
1031
+ self . type_ascribed_value (
1031
1032
|mut this| {
1032
1033
this. write_str ( "pointer" ) ?;
1033
1034
Ok ( this)
1034
1035
} ,
1035
- ty ,
1036
+ |this| this . print_type ( ty ) ,
1036
1037
print_ty,
1037
1038
)
1038
1039
}
@@ -1425,6 +1426,24 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
1425
1426
self . pretty_in_binder ( value)
1426
1427
}
1427
1428
1429
+ fn type_ascribed_value (
1430
+ mut self ,
1431
+ f : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
1432
+ t : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
1433
+ print_ty : bool ,
1434
+ ) -> Result < Self :: Const , Self :: Error > {
1435
+ self . write_str ( "{" ) ?;
1436
+ 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
+ }
1443
+ self . write_str ( "}" ) ?;
1444
+ Ok ( self )
1445
+ }
1446
+
1428
1447
fn generic_delimiters (
1429
1448
mut self ,
1430
1449
f : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
@@ -1488,7 +1507,7 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
1488
1507
ty : Ty < ' tcx > ,
1489
1508
print_ty : bool ,
1490
1509
) -> Result < Self :: Const , Self :: Error > {
1491
- self . print_type_ascribed (
1510
+ self . type_ascribed_value (
1492
1511
|mut this| {
1493
1512
define_scoped_cx ! ( this) ;
1494
1513
if this. print_alloc_ids {
@@ -1498,28 +1517,10 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
1498
1517
}
1499
1518
Ok ( this)
1500
1519
} ,
1501
- ty ,
1520
+ |this| this . print_type ( ty ) ,
1502
1521
print_ty,
1503
1522
)
1504
1523
}
1505
-
1506
- fn print_type_ascribed (
1507
- mut self ,
1508
- f : impl FnOnce ( Self ) -> Result < Self , Self :: Error > ,
1509
- ty : Ty < ' tcx > ,
1510
- print_ty : bool ,
1511
- ) -> Result < Self :: Const , Self :: Error > {
1512
- self . write_str ( "{" ) ?;
1513
- self = f ( self ) ?;
1514
- if print_ty {
1515
- self . write_str ( ": " ) ?;
1516
- let was_in_value = std:: mem:: replace ( & mut self . in_value , false ) ;
1517
- self = self . print_type ( ty) ?;
1518
- self . in_value = was_in_value;
1519
- }
1520
- self . write_str ( "}" ) ?;
1521
- Ok ( self )
1522
- }
1523
1524
}
1524
1525
1525
1526
// HACK(eddyb) limited to `FmtPrinter` because of `region_highlight_mode`.
0 commit comments