@@ -34,33 +34,39 @@ pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStabl
34
34
/// like [`Span`]s and empty tuples, are gracefully skipped so they don't clutter the
35
35
/// representation much.
36
36
pub 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
+
38
42
fn print_attribute ( & self , p : & mut Printer ) ;
39
43
}
40
44
41
45
impl < 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 )
44
48
}
45
49
46
50
fn print_attribute ( & self , p : & mut Printer ) {
47
51
T :: print_attribute ( self , p)
48
52
}
49
53
}
50
54
impl < 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 ( ) )
53
57
}
58
+
54
59
fn print_attribute ( & self , p : & mut Printer ) {
55
60
if let Some ( i) = self {
56
61
T :: print_attribute ( i, p)
57
62
}
58
63
}
59
64
}
60
65
impl < 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 ( )
63
68
}
69
+
64
70
fn print_attribute ( & self , p : & mut Printer ) {
65
71
let mut last_printed = false ;
66
72
p. word ( "[" ) ;
@@ -69,15 +75,15 @@ impl<T: PrintAttribute> PrintAttribute for ThinVec<T> {
69
75
p. word_space ( "," ) ;
70
76
}
71
77
i. print_attribute ( p) ;
72
- last_printed = i. print_something ( ) ;
78
+ last_printed = i. should_render ( ) ;
73
79
}
74
80
p. word ( "]" ) ;
75
81
}
76
82
}
77
83
macro_rules! print_skip {
78
84
( $( $t: ty) ,* $( , ) ?) => { $(
79
85
impl PrintAttribute for $t {
80
- fn print_something ( & self ) -> bool { false }
86
+ fn should_render ( & self ) -> bool { false }
81
87
fn print_attribute( & self , _: & mut Printer ) { }
82
88
} ) *
83
89
} ;
@@ -86,7 +92,7 @@ macro_rules! print_skip {
86
92
macro_rules! print_disp {
87
93
( $( $t: ty) ,* $( , ) ?) => { $(
88
94
impl PrintAttribute for $t {
89
- fn print_something ( & self ) -> bool { true }
95
+ fn should_render ( & self ) -> bool { true }
90
96
fn print_attribute( & self , p: & mut Printer ) {
91
97
p. word( format!( "{}" , self ) ) ;
92
98
}
@@ -96,7 +102,7 @@ macro_rules! print_disp {
96
102
macro_rules! print_debug {
97
103
( $( $t: ty) ,* $( , ) ?) => { $(
98
104
impl PrintAttribute for $t {
99
- fn print_something ( & self ) -> bool { true }
105
+ fn should_render ( & self ) -> bool { true }
100
106
fn print_attribute( & self , p: & mut Printer ) {
101
107
p. word( format!( "{:?}" , self ) ) ;
102
108
}
@@ -105,29 +111,29 @@ macro_rules! print_debug {
105
111
}
106
112
107
113
macro_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 ) * } ;
109
115
( ) => { } ;
110
116
( $t: ident $( $ts: ident) * ) => {
111
117
#[ allow( non_snake_case, unused) ]
112
118
impl <$t: PrintAttribute , $( $ts: PrintAttribute ) ,* > PrintAttribute for ( $t, $( $ts) ,* ) {
113
- fn print_something ( & self ) -> bool {
119
+ fn should_render ( & self ) -> bool {
114
120
let ( $t, $( $ts) ,* ) = self ;
115
- print_tup!( num_print_something $t $( $ts) * ) != 0
121
+ print_tup!( num_should_render $t $( $ts) * ) != 0
116
122
}
117
123
118
124
fn print_attribute( & self , p: & mut Printer ) {
119
125
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 ;
121
127
if parens {
122
128
p. word( "(" ) ;
123
129
}
124
130
125
- let mut printed_anything = $t. print_something ( ) ;
131
+ let mut printed_anything = $t. should_render ( ) ;
126
132
127
133
$t. print_attribute( p) ;
128
134
129
135
$(
130
- if printed_anything && $ts. print_something ( ) {
136
+ if $ts. should_render ( ) {
131
137
p. word_space( "," ) ;
132
138
printed_anything = true ;
133
139
}
0 commit comments