Auto merge of #85515 - jedel1043:fix-85480, r=petrochenkov

Fix ast pretty printing for anonymous types

Fixes #85480.
This commit is contained in:
bors 2021-05-24 05:39:07 +00:00
commit 68424e2f01
2 changed files with 30 additions and 10 deletions

View File

@ -955,12 +955,12 @@ pub fn print_type(&mut self, ty: &ast::Ty) {
self.pclose();
}
ast::TyKind::AnonymousStruct(ref fields, ..) => {
self.s.word("struct");
self.print_record_struct_body(fields, ty.span);
self.head("struct");
self.print_record_struct_body(&fields, ty.span);
}
ast::TyKind::AnonymousUnion(ref fields, ..) => {
self.s.word("union");
self.print_record_struct_body(fields, ty.span);
self.head("union");
self.print_record_struct_body(&fields, ty.span);
}
ast::TyKind::Paren(ref typ) => {
self.popen();
@ -1397,12 +1397,7 @@ fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) {
}
}
crate fn print_record_struct_body(
&mut self,
fields: &Vec<ast::FieldDef>,
span: rustc_span::Span,
) {
self.nbsp();
crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
self.bopen();
self.hardbreak_if_not_bol();
@ -1451,6 +1446,7 @@ fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) {
}
ast::VariantData::Struct(ref fields, ..) => {
self.print_where_clause(&generics.where_clause);
self.nbsp();
self.print_record_struct_body(fields, span);
}
}

View File

@ -0,0 +1,24 @@
// Test for issue 85480
// Pretty print anonymous struct and union types
// pp-exact
// pretty-compare-only
struct Foo {
_: union {
_: struct {
a: u8,
b: u16,
},
c: u32,
},
d: u64,
e: f32,
}
type A =
struct {
field: u8,
};
fn main() { }