Skip to content

Commit 23f6220

Browse files
Mark Wielaardphilberty
Mark Wielaard
authored andcommitted
Handle empty/unit tuple structs in the parser.
A tuple struct can be empty, in which case it is a unit tuple struct. Handle this in Parser<ManagedTokenSource>::parse_struct by creating a empty tuple_field vector instead of calling parse_tuple_fields. Add a testcase to show empty tuple structs are now accepted. Addresses: #385
1 parent 4e5baf7 commit 23f6220

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

gcc/rust/parse/rust-parse-impl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -3980,7 +3980,12 @@ Parser<ManagedTokenSource>::parse_struct (AST::Visibility vis,
39803980
lexer.skip_token ();
39813981

39823982
// parse tuple fields
3983-
std::vector<AST::TupleField> tuple_fields = parse_tuple_fields ();
3983+
std::vector<AST::TupleField> tuple_fields;
3984+
// Might be empty tuple for unit tuple struct.
3985+
if (lexer.peek_token ()->get_id () == RIGHT_PAREN)
3986+
tuple_fields = std::vector<AST::TupleField> ();
3987+
else
3988+
tuple_fields = parse_tuple_fields ();
39843989

39853990
// tuple parameters must have closing parenthesis
39863991
if (!skip_token (RIGHT_PAREN))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct E();
2+
struct T(E,E,());
3+
4+
fn main()
5+
{
6+
let z0 = E();
7+
let z1 = E();
8+
let t = T(z0,z1,());
9+
let z = t.2;
10+
z
11+
}

0 commit comments

Comments
 (0)