Parse unnamed fields and anonymous structs or unions

Anonymous structs or unions are only allowed in struct field
definitions.

Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
This commit is contained in:
Frank King 2023-08-23 20:53:47 +08:00
parent 00b60cdd46
commit cef3117302
2 changed files with 21 additions and 0 deletions

View File

@ -819,6 +819,8 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
ast::TyKind::Tup(ref items) => {
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
}
ast::TyKind::AnonStruct(_) => Some(context.snippet(self.span).to_owned()),
ast::TyKind::AnonUnion(_) => Some(context.snippet(self.span).to_owned()),
ast::TyKind::Path(ref q_self, ref path) => {
rewrite_path(context, PathContext::Type, q_self, path, shape)
}

View File

@ -0,0 +1,19 @@
// 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,
}
fn main() {}