Skip to content

Commit 23e748d

Browse files
bors[bot]Mark Wielaard
and
Mark Wielaard
authored
Merge #522
522: Handle empty/unit tuple enum variants in the parser. r=philberty a=philberty A tuple enum variant can be empty, in which case it is a unit enum variant. Handle this in Parser<ManagedTokenSource>::parse_enum_item by creating a empty tuple_field vector instead of calling parse_tuple_fields. Add a testcase to show empty tuple enum variant types are now accepted. But note some part of the test is commented out because using the enum type isn't actually possible right now. Addresses #79 Co-authored-by: Mark Wielaard <[email protected]>
2 parents 595ae77 + c41d5a2 commit 23e748d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -4415,7 +4415,12 @@ Parser<ManagedTokenSource>::parse_enum_item ()
44154415
// tuple enum item
44164416
lexer.skip_token ();
44174417

4418-
std::vector<AST::TupleField> tuple_fields = parse_tuple_fields ();
4418+
std::vector<AST::TupleField> tuple_fields;
4419+
// Might be empty tuple for unit tuple enum variant.
4420+
if (lexer.peek_token ()->get_id () == RIGHT_PAREN)
4421+
tuple_fields = std::vector<AST::TupleField> ();
4422+
else
4423+
tuple_fields = parse_tuple_fields ();
44194424

44204425
if (!skip_token (RIGHT_PAREN))
44214426
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
enum E { T0(), T1(i32), T2(i32,u32) }
2+
3+
/* The following doesn't parse yet...
4+
fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
5+
{
6+
let e = e0;
7+
let f = e1;
8+
let g = e2;
9+
(e,f,g,())
10+
}
11+
12+
fn main()
13+
{
14+
let e0 = E::T0();
15+
let e1 = E::T1(0);
16+
let e2 = E::T2(0,1);
17+
f(e0, e1, e2).3
18+
}
19+
*/

0 commit comments

Comments
 (0)