diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-23 16:24:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-23 16:24:39 +0000 |
commit | 595ae7743c93bfda40a5914d15ae0db2e7e57301 (patch) | |
tree | 7011e1532b856d9e3beb2062ddf2dd1d5f5c169e | |
parent | 4e5baf7e679a890c22804d16b99fc6794486825b (diff) | |
parent | 23f622047ec24aa15b98fecbfc9376f6bafcd8cb (diff) | |
download | gcc-595ae7743c93bfda40a5914d15ae0db2e7e57301.zip gcc-595ae7743c93bfda40a5914d15ae0db2e7e57301.tar.gz gcc-595ae7743c93bfda40a5914d15ae0db2e7e57301.tar.bz2 |
Merge #521
521: Handle empty/unit tuple structs in the parser. r=philberty a=philberty
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
Co-authored-by: Mark Wielaard <mark@klomp.org>
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 7 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/tuple_struct_unit.rs | 11 |
2 files changed, 17 insertions, 1 deletions
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<ManagedTokenSource>::parse_struct (AST::Visibility vis, lexer.skip_token (); // parse tuple fields - std::vector<AST::TupleField> tuple_fields = parse_tuple_fields (); + std::vector<AST::TupleField> tuple_fields; + // Might be empty tuple for unit tuple struct. + if (lexer.peek_token ()->get_id () == RIGHT_PAREN) + tuple_fields = std::vector<AST::TupleField> (); + else + tuple_fields = parse_tuple_fields (); // tuple parameters must have closing parenthesis if (!skip_token (RIGHT_PAREN)) diff --git a/gcc/testsuite/rust/compile/torture/tuple_struct_unit.rs b/gcc/testsuite/rust/compile/torture/tuple_struct_unit.rs new file mode 100644 index 0000000..cda19d2 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/tuple_struct_unit.rs @@ -0,0 +1,11 @@ +struct E(); +struct T(E,E,()); + +fn main() +{ + let z0 = E(); + let z1 = E(); + let t = T(z0,z1,()); + let z = t.2; + z +} |