Skip to content

Commit cef3117

Browse files
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>
1 parent 00b60cd commit cef3117

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ impl Rewrite for ast::Ty {
819819
ast::TyKind::Tup(ref items) => {
820820
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
821821
}
822+
ast::TyKind::AnonStruct(_) => Some(context.snippet(self.span).to_owned()),
823+
ast::TyKind::AnonUnion(_) => Some(context.snippet(self.span).to_owned()),
822824
ast::TyKind::Path(ref q_self, ref path) => {
823825
rewrite_path(context, PathContext::Type, q_self, path, shape)
824826
}

tests/target/anonymous-types.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
fn main() {}

0 commit comments

Comments
 (0)