@@ -19,20 +19,19 @@ use std::ops::{Deref, DerefMut};
1919// `pretty` is a separate module only for organization.
2020use super :: * ;
2121
22- macro_rules! print_inner {
23- ( write ( $( $data: expr) ,+) ) => {
22+ macro_rules! p {
23+ ( @ write( $( $data: expr) ,+) ) => {
2424 write!( scoped_cx!( ) , $( $data) ,+) ?
2525 } ;
26- ( $kind : ident ( $data : expr) ) => {
27- scoped_cx!( ) = $data . $kind ( scoped_cx!( ) ) ?
26+ ( @print ( $x : expr) ) => {
27+ scoped_cx!( ) = $x . print ( scoped_cx!( ) ) ?
2828 } ;
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) ,* ) ?
3531 } ;
32+ ( $( $kind: ident $data: tt) ,+) => { {
33+ $( p!( @$kind $data) ; ) +
34+ } } ;
3635}
3736macro_rules! define_scoped_cx {
3837 ( $cx: ident) => {
@@ -474,9 +473,8 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
474473 }
475474 ty:: FnDef ( def_id, substs) => {
476475 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( "}}" ) ) ;
480478 }
481479 ty:: FnPtr ( ref bare_fn) => {
482480 p ! ( print( bare_fn) )
@@ -498,7 +496,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
498496 }
499497 }
500498 ty:: Adt ( def, substs) => {
501- self = self . print_def_path ( def. did , Some ( substs) ) ? ;
499+ p ! ( print_def_path( def. did, Some ( substs) ) ) ;
502500 }
503501 ty:: Dynamic ( data, r) => {
504502 let print_r = self . region_should_not_be_omitted ( r) ;
@@ -511,7 +509,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
511509 }
512510 }
513511 ty:: Foreign ( def_id) => {
514- self = self . print_def_path ( def_id, None ) ? ;
512+ p ! ( print_def_path( def_id, None ) ) ;
515513 }
516514 ty:: Projection ( ref data) => p ! ( print( data) ) ,
517515 ty:: UnnormalizedProjection ( ref data) => {
@@ -612,7 +610,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
612610 p ! ( write( " " ) , print( witness) , write( "]" ) )
613611 } ,
614612 ty:: GeneratorWitness ( types) => {
615- self = self . in_binder ( & types) ? ;
613+ p ! ( in_binder( & types) ) ;
616614 }
617615 ty:: Closure ( did, substs) => {
618616 let upvar_tys = substs. upvar_tys ( did, self . tcx ( ) ) ;
@@ -684,7 +682,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
684682 let mut first = true ;
685683
686684 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 ) ) ;
688686
689687 let mut resugared = false ;
690688
@@ -694,7 +692,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
694692 if let ty:: Tuple ( ref args) = principal. substs . type_at ( 0 ) . sty {
695693 let mut projections = predicates. projection_bounds ( ) ;
696694 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) ) ;
698696 resugared = true ;
699697 }
700698 }
@@ -733,13 +731,13 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
733731 let args = arg0. into_iter ( ) . chain ( args) ;
734732 let projections = projection0. into_iter ( ) . chain ( projections) ;
735733
736- self = self . generic_delimiters ( |mut cx| {
734+ p ! ( generic_delimiters( |mut cx| {
737735 cx = cx. comma_sep( args) ?;
738736 if arg0. is_some( ) && projection0. is_some( ) {
739737 write!( cx, ", " ) ?;
740738 }
741739 cx. comma_sep( projections)
742- } ) ? ;
740+ } ) ) ;
743741 }
744742 }
745743 first = false ;
@@ -767,7 +765,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
767765 }
768766 first = false ;
769767
770- self = self . print_def_path ( def_id, None ) ? ;
768+ p ! ( print_def_path( def_id, None ) ) ;
771769 }
772770
773771 Ok ( self )
@@ -1468,7 +1466,7 @@ define_print_and_forward_display! {
14681466 ty:: ExistentialPredicate :: Trait ( x) => p!( print( x) ) ,
14691467 ty:: ExistentialPredicate :: Projection ( x) => p!( print( x) ) ,
14701468 ty:: ExistentialPredicate :: AutoTrait ( def_id) => {
1471- cx = cx . print_def_path( def_id, None ) ? ;
1469+ p! ( print_def_path( def_id, None ) ) ;
14721470 }
14731471 }
14741472 }
@@ -1482,8 +1480,7 @@ define_print_and_forward_display! {
14821480 p!( write( "extern {} " , self . abi) ) ;
14831481 }
14841482
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( ) ) ) ;
14871484 }
14881485
14891486 ty:: InferTy {
@@ -1502,7 +1499,7 @@ define_print_and_forward_display! {
15021499 }
15031500
15041501 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) ) ) ;
15061503 }
15071504
15081505 ty:: ParamTy {
@@ -1522,7 +1519,7 @@ define_print_and_forward_display! {
15221519 }
15231520
15241521 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) ) ) ;
15261523 }
15271524
15281525 ty:: ClosureKind {
@@ -1542,19 +1539,19 @@ define_print_and_forward_display! {
15421539 ty:: Predicate :: Projection ( ref predicate) => p!( print( predicate) ) ,
15431540 ty:: Predicate :: WellFormed ( ty) => p!( print( ty) , write( " well-formed" ) ) ,
15441541 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" ) )
15481545 }
15491546 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) )
15531550 }
15541551 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" ) )
15581555 }
15591556 }
15601557 }
0 commit comments