@@ -19,20 +19,19 @@ use std::ops::{Deref, DerefMut};
19
19
// `pretty` is a separate module only for organization.
20
20
use super :: * ;
21
21
22
- macro_rules! print_inner {
23
- ( write ( $( $data: expr) ,+) ) => {
22
+ macro_rules! p {
23
+ ( @ write( $( $data: expr) ,+) ) => {
24
24
write!( scoped_cx!( ) , $( $data) ,+) ?
25
25
} ;
26
- ( $kind : ident ( $data : expr) ) => {
27
- scoped_cx!( ) = $data . $kind ( scoped_cx!( ) ) ?
26
+ ( @print ( $x : expr) ) => {
27
+ scoped_cx!( ) = $x . print ( scoped_cx!( ) ) ?
28
28
} ;
29
- }
30
- macro_rules! p {
31
- ( $( $kind: ident $data: tt) ,+) => {
32
- {
33
- $( print_inner!( $kind $data) ) ;+
34
- }
29
+ ( @$method: ident( $( $arg: expr) ,* ) ) => {
30
+ scoped_cx!( ) = scoped_cx!( ) . $method( $( $arg) ,* ) ?
35
31
} ;
32
+ ( $( $kind: ident $data: tt) ,+) => { {
33
+ $( p!( @$kind $data) ; ) +
34
+ } } ;
36
35
}
37
36
macro_rules! define_scoped_cx {
38
37
( $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 ( ) ) ;
@@ -693,7 +691,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
693
691
let mut first = true ;
694
692
695
693
if let Some ( principal) = predicates. principal ( ) {
696
- self = self . print_def_path ( principal. def_id , None ) ? ;
694
+ p ! ( print_def_path( principal. def_id, None ) ) ;
697
695
698
696
let mut resugared = false ;
699
697
@@ -703,7 +701,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
703
701
if let ty:: Tuple ( ref args) = principal. substs . type_at ( 0 ) . sty {
704
702
let mut projections = predicates. projection_bounds ( ) ;
705
703
if let ( Some ( proj) , None ) = ( projections. next ( ) , projections. next ( ) ) {
706
- self = self . pretty_fn_sig ( args, false , proj. ty ) ? ;
704
+ p ! ( pretty_fn_sig( args, false , proj. ty) ) ;
707
705
resugared = true ;
708
706
}
709
707
}
@@ -742,13 +740,13 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
742
740
let args = arg0. into_iter ( ) . chain ( args) ;
743
741
let projections = projection0. into_iter ( ) . chain ( projections) ;
744
742
745
- self = self . generic_delimiters ( |mut cx| {
743
+ p ! ( generic_delimiters( |mut cx| {
746
744
cx = cx. comma_sep( args) ?;
747
745
if arg0. is_some( ) && projection0. is_some( ) {
748
746
write!( cx, ", " ) ?;
749
747
}
750
748
cx. comma_sep( projections)
751
- } ) ? ;
749
+ } ) ) ;
752
750
}
753
751
}
754
752
first = false ;
@@ -776,7 +774,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
776
774
}
777
775
first = false ;
778
776
779
- self = self . print_def_path ( def_id, None ) ? ;
777
+ p ! ( print_def_path( def_id, None ) ) ;
780
778
}
781
779
782
780
Ok ( self )
@@ -1478,7 +1476,7 @@ define_print_and_forward_display! {
1478
1476
ty:: ExistentialPredicate :: Trait ( x) => p!( print( x) ) ,
1479
1477
ty:: ExistentialPredicate :: Projection ( x) => p!( print( x) ) ,
1480
1478
ty:: ExistentialPredicate :: AutoTrait ( def_id) => {
1481
- cx = cx . print_def_path( def_id, None ) ? ;
1479
+ p! ( print_def_path( def_id, None ) ) ;
1482
1480
}
1483
1481
}
1484
1482
}
@@ -1492,8 +1490,7 @@ define_print_and_forward_display! {
1492
1490
p!( write( "extern {} " , self . abi) ) ;
1493
1491
}
1494
1492
1495
- p!( write( "fn" ) ) ;
1496
- cx = cx. pretty_fn_sig( self . inputs( ) , self . c_variadic, self . output( ) ) ?;
1493
+ p!( write( "fn" ) , pretty_fn_sig( self . inputs( ) , self . c_variadic, self . output( ) ) ) ;
1497
1494
}
1498
1495
1499
1496
ty:: InferTy {
@@ -1512,7 +1509,7 @@ define_print_and_forward_display! {
1512
1509
}
1513
1510
1514
1511
ty:: TraitRef <' tcx> {
1515
- cx = cx . print_def_path( self . def_id, Some ( self . substs) ) ? ;
1512
+ p! ( print_def_path( self . def_id, Some ( self . substs) ) ) ;
1516
1513
}
1517
1514
1518
1515
ConstValue <' tcx> {
@@ -1556,7 +1553,7 @@ define_print_and_forward_display! {
1556
1553
}
1557
1554
1558
1555
ty:: ProjectionTy <' tcx> {
1559
- cx = cx . print_def_path( self . item_def_id, Some ( self . substs) ) ? ;
1556
+ p! ( print_def_path( self . item_def_id, Some ( self . substs) ) ) ;
1560
1557
}
1561
1558
1562
1559
ty:: ClosureKind {
@@ -1576,19 +1573,19 @@ define_print_and_forward_display! {
1576
1573
ty:: Predicate :: Projection ( ref predicate) => p!( print( predicate) ) ,
1577
1574
ty:: Predicate :: WellFormed ( ty) => p!( print( ty) , write( " well-formed" ) ) ,
1578
1575
ty:: Predicate :: ObjectSafe ( trait_def_id) => {
1579
- p!( write( "the trait `" ) ) ;
1580
- cx = cx . print_def_path( trait_def_id, None ) ? ;
1581
- p! ( write( "` is object-safe" ) )
1576
+ p!( write( "the trait `" ) ,
1577
+ print_def_path( trait_def_id, None ) ,
1578
+ write( "` is object-safe" ) )
1582
1579
}
1583
1580
ty:: Predicate :: ClosureKind ( closure_def_id, _closure_substs, kind) => {
1584
- p!( write( "the closure `" ) ) ;
1585
- cx = cx . print_value_path( closure_def_id, None ) ? ;
1586
- p! ( write( "` implements the trait `{}`" , kind) )
1581
+ p!( write( "the closure `" ) ,
1582
+ print_value_path( closure_def_id, None ) ,
1583
+ write( "` implements the trait `{}`" , kind) )
1587
1584
}
1588
1585
ty:: Predicate :: ConstEvaluatable ( def_id, substs) => {
1589
- p!( write( "the constant `" ) ) ;
1590
- cx = cx . print_value_path( def_id, Some ( substs) ) ? ;
1591
- p! ( write( "` can be evaluated" ) )
1586
+ p!( write( "the constant `" ) ,
1587
+ print_value_path( def_id, Some ( substs) ) ,
1588
+ write( "` can be evaluated" ) )
1592
1589
}
1593
1590
}
1594
1591
}
0 commit comments