diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d6f18fda8b25c..d9e75a4aae32c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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); @@ -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(","); diff --git a/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs b/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs new file mode 100644 index 0000000000000..c2aa0c48d05a7 --- /dev/null +++ b/src/test/pretty/issue-68710-field-attr-proc-mac-lost.rs @@ -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,};