@@ -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) => {
@@ -474,9 +473,8 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
474
473
}
475
474
ty:: FnDef ( def_id, substs) => {
476
475
let sig = self . tcx ( ) . fn_sig ( def_id) . subst ( self . tcx ( ) , substs) ;
477
- p ! ( print( sig) , write( " {{" ) ) ;
478
- self = self . print_value_path ( def_id, Some ( substs) ) ?;
479
- p ! ( write( "}}" ) )
476
+ p ! ( print( sig) ,
477
+ write( " {{" ) , print_value_path( def_id, Some ( substs) ) , write( "}}" ) ) ;
480
478
}
481
479
ty:: FnPtr ( ref bare_fn) => {
482
480
p ! ( print( bare_fn) )
@@ -498,7 +496,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
498
496
}
499
497
}
500
498
ty:: Adt ( def, substs) => {
501
- self = self . print_def_path ( def. did , Some ( substs) ) ? ;
499
+ p ! ( print_def_path( def. did, Some ( substs) ) ) ;
502
500
}
503
501
ty:: Dynamic ( data, r) => {
504
502
let print_r = self . region_should_not_be_omitted ( r) ;
@@ -511,7 +509,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
511
509
}
512
510
}
513
511
ty:: Foreign ( def_id) => {
514
- self = self . print_def_path ( def_id, None ) ? ;
512
+ p ! ( print_def_path( def_id, None ) ) ;
515
513
}
516
514
ty:: Projection ( ref data) => p ! ( print( data) ) ,
517
515
ty:: UnnormalizedProjection ( ref data) => {
@@ -612,7 +610,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
612
610
p ! ( write( " " ) , print( witness) , write( "]" ) )
613
611
} ,
614
612
ty:: GeneratorWitness ( types) => {
615
- self = self . in_binder ( & types) ? ;
613
+ p ! ( in_binder( & types) ) ;
616
614
}
617
615
ty:: Closure ( did, substs) => {
618
616
let upvar_tys = substs. upvar_tys ( did, self . tcx ( ) ) ;
@@ -684,7 +682,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
684
682
let mut first = true ;
685
683
686
684
if let Some ( principal) = predicates. principal ( ) {
687
- self = self . print_def_path ( principal. def_id , None ) ? ;
685
+ p ! ( print_def_path( principal. def_id, None ) ) ;
688
686
689
687
let mut resugared = false ;
690
688
@@ -694,7 +692,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
694
692
if let ty:: Tuple ( ref args) = principal. substs . type_at ( 0 ) . sty {
695
693
let mut projections = predicates. projection_bounds ( ) ;
696
694
if let ( Some ( proj) , None ) = ( projections. next ( ) , projections. next ( ) ) {
697
- self = self . pretty_fn_sig ( args, false , proj. ty ) ? ;
695
+ p ! ( pretty_fn_sig( args, false , proj. ty) ) ;
698
696
resugared = true ;
699
697
}
700
698
}
@@ -733,13 +731,13 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
733
731
let args = arg0. into_iter ( ) . chain ( args) ;
734
732
let projections = projection0. into_iter ( ) . chain ( projections) ;
735
733
736
- self = self . generic_delimiters ( |mut cx| {
734
+ p ! ( generic_delimiters( |mut cx| {
737
735
cx = cx. comma_sep( args) ?;
738
736
if arg0. is_some( ) && projection0. is_some( ) {
739
737
write!( cx, ", " ) ?;
740
738
}
741
739
cx. comma_sep( projections)
742
- } ) ? ;
740
+ } ) ) ;
743
741
}
744
742
}
745
743
first = false ;
@@ -767,7 +765,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
767
765
}
768
766
first = false ;
769
767
770
- self = self . print_def_path ( def_id, None ) ? ;
768
+ p ! ( print_def_path( def_id, None ) ) ;
771
769
}
772
770
773
771
Ok ( self )
@@ -1468,7 +1466,7 @@ define_print_and_forward_display! {
1468
1466
ty:: ExistentialPredicate :: Trait ( x) => p!( print( x) ) ,
1469
1467
ty:: ExistentialPredicate :: Projection ( x) => p!( print( x) ) ,
1470
1468
ty:: ExistentialPredicate :: AutoTrait ( def_id) => {
1471
- cx = cx . print_def_path( def_id, None ) ? ;
1469
+ p! ( print_def_path( def_id, None ) ) ;
1472
1470
}
1473
1471
}
1474
1472
}
@@ -1482,8 +1480,7 @@ define_print_and_forward_display! {
1482
1480
p!( write( "extern {} " , self . abi) ) ;
1483
1481
}
1484
1482
1485
- p!( write( "fn" ) ) ;
1486
- cx = cx. pretty_fn_sig( self . inputs( ) , self . variadic, self . output( ) ) ?;
1483
+ p!( write( "fn" ) , pretty_fn_sig( self . inputs( ) , self . variadic, self . output( ) ) ) ;
1487
1484
}
1488
1485
1489
1486
ty:: InferTy {
@@ -1502,7 +1499,7 @@ define_print_and_forward_display! {
1502
1499
}
1503
1500
1504
1501
ty:: TraitRef <' tcx> {
1505
- cx = cx . print_def_path( self . def_id, Some ( self . substs) ) ? ;
1502
+ p! ( print_def_path( self . def_id, Some ( self . substs) ) ) ;
1506
1503
}
1507
1504
1508
1505
ty:: ParamTy {
@@ -1522,7 +1519,7 @@ define_print_and_forward_display! {
1522
1519
}
1523
1520
1524
1521
ty:: ProjectionTy <' tcx> {
1525
- cx = cx . print_def_path( self . item_def_id, Some ( self . substs) ) ? ;
1522
+ p! ( print_def_path( self . item_def_id, Some ( self . substs) ) ) ;
1526
1523
}
1527
1524
1528
1525
ty:: ClosureKind {
@@ -1542,19 +1539,19 @@ define_print_and_forward_display! {
1542
1539
ty:: Predicate :: Projection ( ref predicate) => p!( print( predicate) ) ,
1543
1540
ty:: Predicate :: WellFormed ( ty) => p!( print( ty) , write( " well-formed" ) ) ,
1544
1541
ty:: Predicate :: ObjectSafe ( trait_def_id) => {
1545
- p!( write( "the trait `" ) ) ;
1546
- cx = cx . print_def_path( trait_def_id, None ) ? ;
1547
- p! ( write( "` is object-safe" ) )
1542
+ p!( write( "the trait `" ) ,
1543
+ print_def_path( trait_def_id, None ) ,
1544
+ write( "` is object-safe" ) )
1548
1545
}
1549
1546
ty:: Predicate :: ClosureKind ( closure_def_id, _closure_substs, kind) => {
1550
- p!( write( "the closure `" ) ) ;
1551
- cx = cx . print_value_path( closure_def_id, None ) ? ;
1552
- p! ( write( "` implements the trait `{}`" , kind) )
1547
+ p!( write( "the closure `" ) ,
1548
+ print_value_path( closure_def_id, None ) ,
1549
+ write( "` implements the trait `{}`" , kind) )
1553
1550
}
1554
1551
ty:: Predicate :: ConstEvaluatable ( def_id, substs) => {
1555
- p!( write( "the constant `" ) ) ;
1556
- cx = cx . print_value_path( def_id, Some ( substs) ) ? ;
1557
- p! ( write( "` can be evaluated" ) )
1552
+ p!( write( "the constant `" ) ,
1553
+ print_value_path( def_id, Some ( substs) ) ,
1554
+ write( "` can be evaluated" ) )
1558
1555
}
1559
1556
}
1560
1557
}
0 commit comments