Skip to content

Commit 0bb7bd4

Browse files
authored
Rollup merge of rust-lang#68737 - Centril:fix-68710, r=petrochenkov
pretty: print attrs in struct expr Fixes rust-lang#68710 by printing the attributes on struct expression fields. r? @petrochenkov cc @dtolnay
2 parents 65c719c + 103e87c commit 0bb7bd4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/libsyntax/print/pprust.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1751,12 +1751,15 @@ impl<'a> State<'a> {
17511751
attrs: &[Attribute],
17521752
) {
17531753
self.print_path(path, true, 0);
1754+
self.nbsp();
17541755
self.s.word("{");
17551756
self.print_inner_attributes_inline(attrs);
17561757
self.commasep_cmnt(
17571758
Consistent,
17581759
&fields[..],
17591760
|s, field| {
1761+
s.print_outer_attributes(&field.attrs);
1762+
s.space_if_not_bol();
17601763
s.ibox(INDENT_UNIT);
17611764
if !field.is_shorthand {
17621765
s.print_ident(field.ident);
@@ -1769,6 +1772,7 @@ impl<'a> State<'a> {
17691772
);
17701773
match *wth {
17711774
Some(ref expr) => {
1775+
self.space_if_not_bol();
17721776
self.ibox(INDENT_UNIT);
17731777
if !fields.is_empty() {
17741778
self.s.word(",");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// pp-exact
2+
3+
fn main() { }
4+
5+
struct C {
6+
field: u8,
7+
}
8+
9+
#[allow()]
10+
const C: C =
11+
C {
12+
#[cfg(debug_assertions)]
13+
field: 0,
14+
15+
#[cfg(not (debug_assertions))]
16+
field: 1,};

0 commit comments

Comments
 (0)