@@ -53,7 +53,6 @@ macro_rules! p {
53
53
}
54
54
macro_rules! define_scoped_cx {
55
55
( $cx: ident) => {
56
- #[ allow( unused_macros) ]
57
56
macro_rules! scoped_cx {
58
57
( ) => {
59
58
$cx
@@ -408,8 +407,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
408
407
def_id : DefId ,
409
408
callers : & mut Vec < DefId > ,
410
409
) -> Result < bool , PrintError > {
411
- define_scoped_cx ! ( self ) ;
412
-
413
410
debug ! ( "try_print_visible_def_path: def_id={:?}" , def_id) ;
414
411
415
412
// If `def_id` is a direct or injected extern crate, return the
@@ -1868,8 +1865,6 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
1868
1865
def_id : DefId ,
1869
1866
args : & ' tcx [ GenericArg < ' tcx > ] ,
1870
1867
) -> Result < ( ) , PrintError > {
1871
- define_scoped_cx ! ( self ) ;
1872
-
1873
1868
if args. is_empty ( ) {
1874
1869
match self . try_print_trimmed_def_path ( def_id) ? {
1875
1870
true => return Ok ( ( ) ) ,
@@ -2401,8 +2396,6 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2401
2396
let _ = write ! ( cx, "{cont}" ) ;
2402
2397
} ;
2403
2398
2404
- define_scoped_cx ! ( self ) ;
2405
-
2406
2399
let possible_names = ( 'a' ..='z' ) . rev ( ) . map ( |s| Symbol :: intern ( & format ! ( "'{s}" ) ) ) ;
2407
2400
2408
2401
let mut available_names = possible_names
@@ -2630,46 +2623,6 @@ where
2630
2623
}
2631
2624
}
2632
2625
2633
- macro_rules! forward_display_to_print {
2634
- ( $( $ty: ty) ,+) => {
2635
- // Some of the $ty arguments may not actually use 'tcx
2636
- $( #[ allow( unused_lifetimes) ] impl <' tcx> fmt:: Display for $ty {
2637
- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
2638
- ty:: tls:: with( |tcx| {
2639
- let mut cx = FmtPrinter :: new( tcx, Namespace :: TypeNS ) ;
2640
- tcx. lift( * self )
2641
- . expect( "could not lift for printing" )
2642
- . print( & mut cx) ?;
2643
- f. write_str( & cx. into_buffer( ) ) ?;
2644
- Ok ( ( ) )
2645
- } )
2646
- }
2647
- } ) +
2648
- } ;
2649
- }
2650
-
2651
- macro_rules! define_print_and_forward_display {
2652
- ( ( $self: ident, $cx: ident) : $( $ty: ty $print: block) +) => {
2653
- define_print!( ( $self, $cx) : $( $ty $print) * ) ;
2654
- forward_display_to_print!( $( $ty) ,+) ;
2655
- } ;
2656
- }
2657
-
2658
- macro_rules! define_print {
2659
- ( ( $self: ident, $cx: ident) : $( $ty: ty $print: block) +) => {
2660
- $( impl <' tcx, P : PrettyPrinter <' tcx>> Print <' tcx, P > for $ty {
2661
- fn print( & $self, $cx: & mut P ) -> Result <( ) , PrintError > {
2662
- #[ allow( unused_mut) ]
2663
- let mut $cx = $cx;
2664
- define_scoped_cx!( $cx) ;
2665
- let _: ( ) = $print;
2666
- #[ allow( unreachable_code) ]
2667
- Ok ( ( ) )
2668
- }
2669
- } ) +
2670
- } ;
2671
- }
2672
-
2673
2626
/// Wrapper type for `ty::TraitRef` which opts-in to pretty printing only
2674
2627
/// the trait path. That is, it will print `Trait<U>` instead of
2675
2628
/// `<T as Trait<U>>`.
@@ -2744,6 +2697,43 @@ pub struct PrintClosureAsImpl<'tcx> {
2744
2697
pub closure : ty:: ClosureArgs < ' tcx > ,
2745
2698
}
2746
2699
2700
+ macro_rules! forward_display_to_print {
2701
+ ( $( $ty: ty) ,+) => {
2702
+ // Some of the $ty arguments may not actually use 'tcx
2703
+ $( #[ allow( unused_lifetimes) ] impl <' tcx> fmt:: Display for $ty {
2704
+ fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
2705
+ ty:: tls:: with( |tcx| {
2706
+ let mut cx = FmtPrinter :: new( tcx, Namespace :: TypeNS ) ;
2707
+ tcx. lift( * self )
2708
+ . expect( "could not lift for printing" )
2709
+ . print( & mut cx) ?;
2710
+ f. write_str( & cx. into_buffer( ) ) ?;
2711
+ Ok ( ( ) )
2712
+ } )
2713
+ }
2714
+ } ) +
2715
+ } ;
2716
+ }
2717
+
2718
+ macro_rules! define_print {
2719
+ ( ( $self: ident, $cx: ident) : $( $ty: ty $print: block) +) => {
2720
+ $( impl <' tcx, P : PrettyPrinter <' tcx>> Print <' tcx, P > for $ty {
2721
+ fn print( & $self, $cx: & mut P ) -> Result <( ) , PrintError > {
2722
+ define_scoped_cx!( $cx) ;
2723
+ let _: ( ) = $print;
2724
+ Ok ( ( ) )
2725
+ }
2726
+ } ) +
2727
+ } ;
2728
+ }
2729
+
2730
+ macro_rules! define_print_and_forward_display {
2731
+ ( ( $self: ident, $cx: ident) : $( $ty: ty $print: block) +) => {
2732
+ define_print!( ( $self, $cx) : $( $ty $print) * ) ;
2733
+ forward_display_to_print!( $( $ty) ,+) ;
2734
+ } ;
2735
+ }
2736
+
2747
2737
forward_display_to_print ! {
2748
2738
ty:: Region <' tcx>,
2749
2739
Ty <' tcx>,
0 commit comments