diff options
| author | bors <bors@rust-lang.org> | 2021-05-24 05:39:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-24 05:39:07 +0000 |
| commit | 68424e2f01ef6884af440114f7cf2ed01faf86e3 (patch) | |
| tree | 5585dc2d1d57d780acf27889882c6cca3e366423 | |
| parent | 3f9646da57946ced0b494c3c57ebffdf67136fd9 (diff) | |
| parent | d59b1f1ef4be692b67c1ff1b49ec810fd59452cf (diff) | |
| download | rust-68424e2f01ef6884af440114f7cf2ed01faf86e3.tar.gz rust-68424e2f01ef6884af440114f7cf2ed01faf86e3.zip | |
Auto merge of #85515 - jedel1043:fix-85480, r=petrochenkov
Fix ast pretty printing for anonymous types Fixes #85480.
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 16 | ||||
| -rw-r--r-- | src/test/pretty/anonymous-types.rs | 24 |
2 files changed, 30 insertions, 10 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index da9d89745a8..b7bb896f318 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -955,12 +955,12 @@ impl<'a> State<'a> { 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 @@ impl<'a> State<'a> { } } - 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 @@ impl<'a> State<'a> { } ast::VariantData::Struct(ref fields, ..) => { self.print_where_clause(&generics.where_clause); + self.nbsp(); self.print_record_struct_body(fields, span); } } diff --git a/src/test/pretty/anonymous-types.rs b/src/test/pretty/anonymous-types.rs new file mode 100644 index 00000000000..5ff452e8e43 --- /dev/null +++ b/src/test/pretty/anonymous-types.rs @@ -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() { } |
