Skip to content

Commit 3a3c4db

Browse files
authored
Rollup merge of #145493 - fee1-dead-contrib:push-rsqlqymxyyqp, r=jdonszelmann
remove `should_render` in `PrintAttribute` derive It just seems to be always `true`, so don't do extra work emitting extra logic just for a `true`. cc `@jdonszelmann`
2 parents caabaf7 + 3450975 commit 3a3c4db

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

compiler/rustc_macros/src/print_attribute.rs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syn::spanned::Spanned;
44
use syn::{Data, Fields, Ident};
55
use synstructure::Structure;
66

7-
fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, TokenStream) {
7+
fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream) {
88
let string_name = name.to_string();
99
let mut disps = vec![quote! {let mut __printed_anything = false;}];
1010

@@ -43,7 +43,6 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
4343
#(#disps)*
4444
__p.word("}");
4545
},
46-
quote! { true },
4746
)
4847
}
4948
Fields::Unnamed(fields_unnamed) => {
@@ -76,10 +75,9 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
7675
#(#disps)*
7776
__p.pclose();
7877
},
79-
quote! { true },
8078
)
8179
}
82-
Fields::Unit => (quote! {}, quote! { __p.word(#string_name) }, quote! { true }),
80+
Fields::Unit => (quote! {}, quote! { __p.word(#string_name) }),
8381
}
8482
}
8583

@@ -89,51 +87,33 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
8987
};
9088

9189
// Must be applied to an enum type.
92-
let (code, printed) = match &input.ast().data {
90+
let code = match &input.ast().data {
9391
Data::Enum(e) => {
94-
let (arms, printed) = e
92+
let arms = e
9593
.variants
9694
.iter()
9795
.map(|x| {
9896
let ident = &x.ident;
99-
let (pat, code, printed) = print_fields(ident, &x.fields);
97+
let (pat, code) = print_fields(ident, &x.fields);
10098

101-
(
102-
quote! {
103-
Self::#ident #pat => {#code}
104-
},
105-
quote! {
106-
Self::#ident #pat => {#printed}
107-
},
108-
)
99+
quote! {
100+
Self::#ident #pat => {#code}
101+
}
109102
})
110-
.unzip::<_, _, Vec<_>, Vec<_>>();
103+
.collect::<Vec<_>>();
111104

112-
(
113-
quote! {
114-
match self {
115-
#(#arms)*
116-
}
117-
},
118-
quote! {
119-
match self {
120-
#(#printed)*
121-
}
122-
},
123-
)
105+
quote! {
106+
match self {
107+
#(#arms)*
108+
}
109+
}
124110
}
125111
Data::Struct(s) => {
126-
let (pat, code, printed) = print_fields(&input.ast().ident, &s.fields);
127-
(
128-
quote! {
129-
let Self #pat = self;
130-
#code
131-
},
132-
quote! {
133-
let Self #pat = self;
134-
#printed
135-
},
136-
)
112+
let (pat, code) = print_fields(&input.ast().ident, &s.fields);
113+
quote! {
114+
let Self #pat = self;
115+
#code
116+
}
137117
}
138118
Data::Union(u) => {
139119
return span_error(u.union_token.span(), "can't derive PrintAttribute on unions");
@@ -144,7 +124,7 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
144124
input.gen_impl(quote! {
145125
#[allow(unused)]
146126
gen impl PrintAttribute for @Self {
147-
fn should_render(&self) -> bool { #printed }
127+
fn should_render(&self) -> bool { true }
148128
fn print_attribute(&self, __p: &mut rustc_ast_pretty::pp::Printer) { #code }
149129
}
150130
})

0 commit comments

Comments
 (0)