diff options
| author | Michael Goulet <michael@errs.io> | 2025-03-05 15:20:16 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-03-10 02:04:26 +0000 |
| commit | 279377f87aa1871e1011366b6cf997cfa24e3d65 (patch) | |
| tree | 5f9f24231063dabcb8bc1b8d8eb625fa6e462047 /compiler/rustc_macros/src | |
| parent | 6a38322d2608a480b38da6efd926627950bc0537 (diff) | |
| download | rust-279377f87aa1871e1011366b6cf997cfa24e3d65.tar.gz rust-279377f87aa1871e1011366b6cf997cfa24e3d65.zip | |
Fix pretty printing of parsed attrs in hir_pretty
Diffstat (limited to 'compiler/rustc_macros/src')
| -rw-r--r-- | compiler/rustc_macros/src/print_attribute.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/compiler/rustc_macros/src/print_attribute.rs b/compiler/rustc_macros/src/print_attribute.rs index fe78fb15cb9..42d94e72ee9 100644 --- a/compiler/rustc_macros/src/print_attribute.rs +++ b/compiler/rustc_macros/src/print_attribute.rs @@ -16,12 +16,14 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok let name = field.ident.as_ref().unwrap(); let string_name = name.to_string(); disps.push(quote! { - if __printed_anything && #name.should_render() { - __p.word_space(","); + if #name.should_render() { + if __printed_anything { + __p.word_space(","); + } + __p.word(#string_name); + __p.word_space(":"); __printed_anything = true; } - __p.word(#string_name); - __p.word_space(":"); #name.print_attribute(__p); }); field_names.push(name); @@ -35,6 +37,7 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok return; } + __p.nbsp(); __p.word("{"); #(#disps)* __p.word("}"); @@ -48,8 +51,10 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok for idx in 0..fields_unnamed.unnamed.len() { let name = format_ident!("f{idx}"); disps.push(quote! { - if __printed_anything && #name.should_render() { - __p.word_space(","); + if #name.should_render() { + if __printed_anything { + __p.word_space(","); + } __printed_anything = true; } #name.print_attribute(__p); @@ -66,9 +71,9 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok return; } - __p.word("("); + __p.popen(); #(#disps)* - __p.word(")"); + __p.pclose(); }, quote! { true }, ) |
