@@ -18,20 +18,19 @@ use std::ops::{Deref, DerefMut};
18
18
// `pretty` is a separate module only for organization.
19
19
use super :: * ;
20
20
21
- macro_rules! print_inner {
22
- ( write ( $( $data: expr) ,+) ) => {
21
+ macro_rules! p {
22
+ ( @ write( $( $data: expr) ,+) ) => {
23
23
write!( scoped_cx!( ) , $( $data) ,+) ?
24
24
} ;
25
- ( $kind : ident ( $data : expr) ) => {
26
- scoped_cx!( ) = $data . $kind ( scoped_cx!( ) ) ?
25
+ ( @print ( $x : expr) ) => {
26
+ scoped_cx!( ) = $x . print ( scoped_cx!( ) ) ?
27
27
} ;
28
- }
29
- macro_rules! p {
30
- ( $( $kind: ident $data: tt) ,+) => {
31
- {
32
- $( print_inner!( $kind $data) ) ;+
33
- }
28
+ ( @$method: ident( $( $arg: expr) ,* ) ) => {
29
+ scoped_cx!( ) = scoped_cx!( ) . $method( $( $arg) ,* ) ?
34
30
} ;
31
+ ( $( $kind: ident $data: tt) ,+) => { {
32
+ $( p!( @$kind $data) ; ) +
33
+ } } ;
35
34
}
36
35
macro_rules! define_scoped_cx {
37
36
( $cx: ident) => {
@@ -470,9 +469,8 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
470
469
}
471
470
ty:: FnDef ( def_id, substs) => {
472
471
let sig = self . tcx ( ) . fn_sig ( def_id) . subst ( self . tcx ( ) , substs) ;
473
- p ! ( print( sig) , write( " {{" ) ) ;
474
- self = self . print_value_path ( def_id, Some ( substs) ) ?;
475
- p ! ( write( "}}" ) )
472
+ p ! ( print( sig) ,
473
+ write( " {{" ) , print_value_path( def_id, Some ( substs) ) , write( "}}" ) ) ;
476
474
}
477
475
ty:: FnPtr ( ref bare_fn) => {
478
476
p ! ( print( bare_fn) )
@@ -494,7 +492,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
494
492
}
495
493
}
496
494
ty:: Adt ( def, substs) => {
497
- self = self . print_def_path ( def. did , Some ( substs) ) ? ;
495
+ p ! ( print_def_path( def. did, Some ( substs) ) ) ;
498
496
}
499
497
ty:: Dynamic ( data, r) => {
500
498
let print_r = self . region_should_not_be_omitted ( r) ;
@@ -507,7 +505,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
507
505
}
508
506
}
509
507
ty:: Foreign ( def_id) => {
510
- self = self . print_def_path ( def_id, None ) ? ;
508
+ p ! ( print_def_path( def_id, None ) ) ;
511
509
}
512
510
ty:: Projection ( ref data) => p ! ( print( data) ) ,
513
511
ty:: UnnormalizedProjection ( ref data) => {
@@ -608,7 +606,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
608
606
p ! ( write( " " ) , print( witness) , write( "]" ) )
609
607
} ,
610
608
ty:: GeneratorWitness ( types) => {
611
- self = self . in_binder ( & types) ? ;
609
+ p ! ( in_binder( & types) ) ;
612
610
}
613
611
ty:: Closure ( did, substs) => {
614
612
let upvar_tys = substs. upvar_tys ( did, self . tcx ( ) ) ;
@@ -680,7 +678,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
680
678
let mut first = true ;
681
679
682
680
if let Some ( principal) = predicates. principal ( ) {
683
- self = self . print_def_path ( principal. def_id , None ) ? ;
681
+ p ! ( print_def_path( principal. def_id, None ) ) ;
684
682
685
683
let mut resugared = false ;
686
684
@@ -690,7 +688,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
690
688
if let ty:: Tuple ( ref args) = principal. substs . type_at ( 0 ) . sty {
691
689
let mut projections = predicates. projection_bounds ( ) ;
692
690
if let ( Some ( proj) , None ) = ( projections. next ( ) , projections. next ( ) ) {
693
- self = self . pretty_fn_sig ( args, false , proj. ty ) ? ;
691
+ p ! ( pretty_fn_sig( args, false , proj. ty) ) ;
694
692
resugared = true ;
695
693
}
696
694
}
@@ -729,13 +727,13 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
729
727
let args = arg0. into_iter ( ) . chain ( args) ;
730
728
let projections = projection0. into_iter ( ) . chain ( projections) ;
731
729
732
- self = self . generic_delimiters ( |mut cx| {
730
+ p ! ( generic_delimiters( |mut cx| {
733
731
cx = cx. comma_sep( args) ?;
734
732
if arg0. is_some( ) && projection0. is_some( ) {
735
733
write!( cx, ", " ) ?;
736
734
}
737
735
cx. comma_sep( projections)
738
- } ) ? ;
736
+ } ) ) ;
739
737
}
740
738
}
741
739
first = false ;
@@ -763,7 +761,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
763
761
}
764
762
first = false ;
765
763
766
- self = self . print_def_path ( def_id, None ) ? ;
764
+ p ! ( print_def_path( def_id, None ) ) ;
767
765
}
768
766
769
767
Ok ( self )
@@ -1464,7 +1462,7 @@ define_print_and_forward_display! {
1464
1462
ty:: ExistentialPredicate :: Trait ( x) => p!( print( x) ) ,
1465
1463
ty:: ExistentialPredicate :: Projection ( x) => p!( print( x) ) ,
1466
1464
ty:: ExistentialPredicate :: AutoTrait ( def_id) => {
1467
- cx = cx . print_def_path( def_id, None ) ? ;
1465
+ p! ( print_def_path( def_id, None ) ) ;
1468
1466
}
1469
1467
}
1470
1468
}
@@ -1478,8 +1476,7 @@ define_print_and_forward_display! {
1478
1476
p!( write( "extern {} " , self . abi) ) ;
1479
1477
}
1480
1478
1481
- p!( write( "fn" ) ) ;
1482
- cx = cx. pretty_fn_sig( self . inputs( ) , self . variadic, self . output( ) ) ?;
1479
+ p!( write( "fn" ) , pretty_fn_sig( self . inputs( ) , self . variadic, self . output( ) ) ) ;
1483
1480
}
1484
1481
1485
1482
ty:: InferTy {
@@ -1498,7 +1495,7 @@ define_print_and_forward_display! {
1498
1495
}
1499
1496
1500
1497
ty:: TraitRef <' tcx> {
1501
- cx = cx . print_def_path( self . def_id, Some ( self . substs) ) ? ;
1498
+ p! ( print_def_path( self . def_id, Some ( self . substs) ) ) ;
1502
1499
}
1503
1500
1504
1501
ty:: ParamTy {
@@ -1518,7 +1515,7 @@ define_print_and_forward_display! {
1518
1515
}
1519
1516
1520
1517
ty:: ProjectionTy <' tcx> {
1521
- cx = cx . print_def_path( self . item_def_id, Some ( self . substs) ) ? ;
1518
+ p! ( print_def_path( self . item_def_id, Some ( self . substs) ) ) ;
1522
1519
}
1523
1520
1524
1521
ty:: ClosureKind {
@@ -1538,19 +1535,19 @@ define_print_and_forward_display! {
1538
1535
ty:: Predicate :: Projection ( ref predicate) => p!( print( predicate) ) ,
1539
1536
ty:: Predicate :: WellFormed ( ty) => p!( print( ty) , write( " well-formed" ) ) ,
1540
1537
ty:: Predicate :: ObjectSafe ( trait_def_id) => {
1541
- p!( write( "the trait `" ) ) ;
1542
- cx = cx . print_def_path( trait_def_id, None ) ? ;
1543
- p! ( write( "` is object-safe" ) )
1538
+ p!( write( "the trait `" ) ,
1539
+ print_def_path( trait_def_id, None ) ,
1540
+ write( "` is object-safe" ) )
1544
1541
}
1545
1542
ty:: Predicate :: ClosureKind ( closure_def_id, _closure_substs, kind) => {
1546
- p!( write( "the closure `" ) ) ;
1547
- cx = cx . print_value_path( closure_def_id, None ) ? ;
1548
- p! ( write( "` implements the trait `{}`" , kind) )
1543
+ p!( write( "the closure `" ) ,
1544
+ print_value_path( closure_def_id, None ) ,
1545
+ write( "` implements the trait `{}`" , kind) )
1549
1546
}
1550
1547
ty:: Predicate :: ConstEvaluatable ( def_id, substs) => {
1551
- p!( write( "the constant `" ) ) ;
1552
- cx = cx . print_value_path( def_id, Some ( substs) ) ? ;
1553
- p! ( write( "` can be evaluated" ) )
1548
+ p!( write( "the constant `" ) ,
1549
+ print_value_path( def_id, Some ( substs) ) ,
1550
+ write( "` can be evaluated" ) )
1554
1551
}
1555
1552
}
1556
1553
}
0 commit comments