@@ -34,33 +34,39 @@ pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStabl
3434/// like [`Span`]s and empty tuples, are gracefully skipped so they don't clutter the
3535/// representation much.
3636pub trait PrintAttribute {
37- fn print_something ( & self ) -> bool ;
37+ /// Whether or not this will render as something meaningful, or if it's skipped
38+ /// (which will force the containing struct to also skip printing a comma
39+ /// and the field name).
40+ fn should_render ( & self ) -> bool ;
41+
3842 fn print_attribute ( & self , p : & mut Printer ) ;
3943}
4044
4145impl < T : PrintAttribute > PrintAttribute for & T {
42- fn print_something ( & self ) -> bool {
43- T :: print_something ( self )
46+ fn should_render ( & self ) -> bool {
47+ T :: should_render ( self )
4448 }
4549
4650 fn print_attribute ( & self , p : & mut Printer ) {
4751 T :: print_attribute ( self , p)
4852 }
4953}
5054impl < T : PrintAttribute > PrintAttribute for Option < T > {
51- fn print_something ( & self ) -> bool {
52- self . as_ref ( ) . is_some_and ( |x| x. print_something ( ) )
55+ fn should_render ( & self ) -> bool {
56+ self . as_ref ( ) . is_some_and ( |x| x. should_render ( ) )
5357 }
58+
5459 fn print_attribute ( & self , p : & mut Printer ) {
5560 if let Some ( i) = self {
5661 T :: print_attribute ( i, p)
5762 }
5863 }
5964}
6065impl < T : PrintAttribute > PrintAttribute for ThinVec < T > {
61- fn print_something ( & self ) -> bool {
62- self . is_empty ( ) || self [ 0 ] . print_something ( )
66+ fn should_render ( & self ) -> bool {
67+ self . is_empty ( ) || self [ 0 ] . should_render ( )
6368 }
69+
6470 fn print_attribute ( & self , p : & mut Printer ) {
6571 let mut last_printed = false ;
6672 p. word ( "[" ) ;
@@ -69,15 +75,15 @@ impl<T: PrintAttribute> PrintAttribute for ThinVec<T> {
6975 p. word_space ( "," ) ;
7076 }
7177 i. print_attribute ( p) ;
72- last_printed = i. print_something ( ) ;
78+ last_printed = i. should_render ( ) ;
7379 }
7480 p. word ( "]" ) ;
7581 }
7682}
7783macro_rules! print_skip {
7884 ( $( $t: ty) ,* $( , ) ?) => { $(
7985 impl PrintAttribute for $t {
80- fn print_something ( & self ) -> bool { false }
86+ fn should_render ( & self ) -> bool { false }
8187 fn print_attribute( & self , _: & mut Printer ) { }
8288 } ) *
8389 } ;
@@ -86,7 +92,7 @@ macro_rules! print_skip {
8692macro_rules! print_disp {
8793 ( $( $t: ty) ,* $( , ) ?) => { $(
8894 impl PrintAttribute for $t {
89- fn print_something ( & self ) -> bool { true }
95+ fn should_render ( & self ) -> bool { true }
9096 fn print_attribute( & self , p: & mut Printer ) {
9197 p. word( format!( "{}" , self ) ) ;
9298 }
@@ -96,7 +102,7 @@ macro_rules! print_disp {
96102macro_rules! print_debug {
97103 ( $( $t: ty) ,* $( , ) ?) => { $(
98104 impl PrintAttribute for $t {
99- fn print_something ( & self ) -> bool { true }
105+ fn should_render ( & self ) -> bool { true }
100106 fn print_attribute( & self , p: & mut Printer ) {
101107 p. word( format!( "{:?}" , self ) ) ;
102108 }
@@ -105,29 +111,29 @@ macro_rules! print_debug {
105111}
106112
107113macro_rules! print_tup {
108- ( num_print_something $( $ts: ident) * ) => { 0 $( + $ts. print_something ( ) as usize ) * } ;
114+ ( num_should_render $( $ts: ident) * ) => { 0 $( + $ts. should_render ( ) as usize ) * } ;
109115 ( ) => { } ;
110116 ( $t: ident $( $ts: ident) * ) => {
111117 #[ allow( non_snake_case, unused) ]
112118 impl <$t: PrintAttribute , $( $ts: PrintAttribute ) ,* > PrintAttribute for ( $t, $( $ts) ,* ) {
113- fn print_something ( & self ) -> bool {
119+ fn should_render ( & self ) -> bool {
114120 let ( $t, $( $ts) ,* ) = self ;
115- print_tup!( num_print_something $t $( $ts) * ) != 0
121+ print_tup!( num_should_render $t $( $ts) * ) != 0
116122 }
117123
118124 fn print_attribute( & self , p: & mut Printer ) {
119125 let ( $t, $( $ts) ,* ) = self ;
120- let parens = print_tup!( num_print_something $t $( $ts) * ) > 1 ;
126+ let parens = print_tup!( num_should_render $t $( $ts) * ) > 1 ;
121127 if parens {
122128 p. word( "(" ) ;
123129 }
124130
125- let mut printed_anything = $t. print_something ( ) ;
131+ let mut printed_anything = $t. should_render ( ) ;
126132
127133 $t. print_attribute( p) ;
128134
129135 $(
130- if printed_anything && $ts. print_something ( ) {
136+ if $ts. should_render ( ) {
131137 p. word_space( "," ) ;
132138 printed_anything = true ;
133139 }
0 commit comments