From 23f622047ec24aa15b98fecbfc9376f6bafcd8cb Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 23 Jun 2021 18:06:35 +0200 Subject: 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::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 --- gcc/rust/parse/rust-parse-impl.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gcc/rust/parse/rust-parse-impl.h') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index b4f264e..dfac00e 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3980,7 +3980,12 @@ Parser::parse_struct (AST::Visibility vis, lexer.skip_token (); // parse tuple fields - std::vector tuple_fields = parse_tuple_fields (); + std::vector tuple_fields; + // Might be empty tuple for unit tuple struct. + if (lexer.peek_token ()->get_id () == RIGHT_PAREN) + tuple_fields = std::vector (); + else + tuple_fields = parse_tuple_fields (); // tuple parameters must have closing parenthesis if (!skip_token (RIGHT_PAREN)) -- cgit v1.1