Skip to content

Commit

Permalink
Rollup merge of #68737 - Centril:fix-68710, r=petrochenkov
Browse files Browse the repository at this point in the history
pretty: print attrs in struct expr

Fixes #68710 by printing the attributes on struct expression fields.

r? @petrochenkov
cc @dtolnay
  • Loading branch information
Dylan-DPC authored Feb 1, 2020
2 parents 65c719c + 103e87c commit 0bb7bd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,12 +1751,15 @@ impl<'a> State<'a> {
attrs: &[Attribute],
) {
self.print_path(path, true, 0);
self.nbsp();
self.s.word("{");
self.print_inner_attributes_inline(attrs);
self.commasep_cmnt(
Consistent,
&fields[..],
|s, field| {
s.print_outer_attributes(&field.attrs);
s.space_if_not_bol();
s.ibox(INDENT_UNIT);
if !field.is_shorthand {
s.print_ident(field.ident);
Expand All @@ -1769,6 +1772,7 @@ impl<'a> State<'a> {
);
match *wth {
Some(ref expr) => {
self.space_if_not_bol();
self.ibox(INDENT_UNIT);
if !fields.is_empty() {
self.s.word(",");
Expand Down
16 changes: 16 additions & 0 deletions src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// pp-exact

fn main() { }

struct C {
field: u8,
}

#[allow()]
const C: C =
C {
#[cfg(debug_assertions)]
field: 0,

#[cfg(not (debug_assertions))]
field: 1,};

0 comments on commit 0bb7bd4

Please sign in to comment.