diff options
author | Mark Wielaard <mark@klomp.org> | 2021-06-23 22:15:36 +0200 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-06-24 11:07:37 +0100 |
commit | c41d5a20d34d11109142140a7a1db23d67ddf839 (patch) | |
tree | de6518392abf835f285e7951c0656d7394333ba2 /gcc/rust/parse/rust-parse-impl.h | |
parent | 595ae7743c93bfda40a5914d15ae0db2e7e57301 (diff) | |
download | gcc-c41d5a20d34d11109142140a7a1db23d67ddf839.zip gcc-c41d5a20d34d11109142140a7a1db23d67ddf839.tar.gz gcc-c41d5a20d34d11109142140a7a1db23d67ddf839.tar.bz2 |
Handle empty/unit tuple enum variants in the parser.
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.
Diffstat (limited to 'gcc/rust/parse/rust-parse-impl.h')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index dfac00e..9a28f6c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4415,7 +4415,12 @@ Parser<ManagedTokenSource>::parse_enum_item () // tuple enum item lexer.skip_token (); - std::vector<AST::TupleField> tuple_fields = parse_tuple_fields (); + std::vector<AST::TupleField> tuple_fields; + // Might be empty tuple for unit tuple enum variant. + if (lexer.peek_token ()->get_id () == RIGHT_PAREN) + tuple_fields = std::vector<AST::TupleField> (); + else + tuple_fields = parse_tuple_fields (); if (!skip_token (RIGHT_PAREN)) { |