Skip to content

Commit 68424e2

Browse files
committed
Auto merge of #85515 - jedel1043:fix-85480, r=petrochenkov
Fix ast pretty printing for anonymous types Fixes #85480.
2 parents 3f9646d + d59b1f1 commit 68424e2

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,12 @@ impl<'a> State<'a> {
955955
self.pclose();
956956
}
957957
ast::TyKind::AnonymousStruct(ref fields, ..) => {
958-
self.s.word("struct");
959-
self.print_record_struct_body(fields, ty.span);
958+
self.head("struct");
959+
self.print_record_struct_body(&fields, ty.span);
960960
}
961961
ast::TyKind::AnonymousUnion(ref fields, ..) => {
962-
self.s.word("union");
963-
self.print_record_struct_body(fields, ty.span);
962+
self.head("union");
963+
self.print_record_struct_body(&fields, ty.span);
964964
}
965965
ast::TyKind::Paren(ref typ) => {
966966
self.popen();
@@ -1397,12 +1397,7 @@ impl<'a> State<'a> {
13971397
}
13981398
}
13991399

1400-
crate fn print_record_struct_body(
1401-
&mut self,
1402-
fields: &Vec<ast::FieldDef>,
1403-
span: rustc_span::Span,
1404-
) {
1405-
self.nbsp();
1400+
crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
14061401
self.bopen();
14071402
self.hardbreak_if_not_bol();
14081403

@@ -1451,6 +1446,7 @@ impl<'a> State<'a> {
14511446
}
14521447
ast::VariantData::Struct(ref fields, ..) => {
14531448
self.print_where_clause(&generics.where_clause);
1449+
self.nbsp();
14541450
self.print_record_struct_body(fields, span);
14551451
}
14561452
}

src/test/pretty/anonymous-types.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test for issue 85480
2+
// Pretty print anonymous struct and union types
3+
4+
// pp-exact
5+
// pretty-compare-only
6+
7+
struct Foo {
8+
_: union {
9+
_: struct {
10+
a: u8,
11+
b: u16,
12+
},
13+
c: u32,
14+
},
15+
d: u64,
16+
e: f32,
17+
}
18+
19+
type A =
20+
struct {
21+
field: u8,
22+
};
23+
24+
fn main() { }

0 commit comments

Comments
 (0)