From: Mark Wielaard <mark@klomp.org>
To: Philip Herron <philip.herron@embecosm.com>, gcc-rust@gcc.gnu.org
Subject: Re: tuple indexes
Date: Wed, 23 Jun 2021 18:06:35 +0200 [thread overview]
Message-ID: <fcc70f22cf4f37a150da061aa90219cd1d69a97c.camel@klomp.org> (raw)
In-Reply-To: <8e2ce8ca-ff1d-4b25-d3bf-f4f523edef03@embecosm.com>
[-- Attachment #1: Type: text/plain, Size: 658 bytes --]
Hi Philip,
On Wed, 2021-06-23 at 10:55 +0100, Philip Herron wrote:
> Small update, I think part of this issue is that the support for
> unit-structs is not there yet in the compiler, so if you remove the unit
> tuple struct and move the other struct definitions outside of the block
> the test case works: https://godbolt.org/z/nb84sEaE4
>
> It might be enough to help with testing your tuple index fixes.
Very nice. That workaround helps me get unblocked, except for testing
empty struct tuples (unit-structs). But I have a patch for that, and
even included a testcase to proof the parser now handles them. See
attached.
Cheers,
Mark
[-- Attachment #2: 0001-Handle-empty-unit-tuple-structs-in-the-parser.patch --]
[-- Type: text/x-patch, Size: 1939 bytes --]
From a1d03b5182f7e2b16b5201459c98b33a12775888 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Wed, 23 Jun 2021 17:59:30 +0200
Subject: [PATCH] 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.
---
gcc/rust/parse/rust-parse-impl.h | 7 ++++++-
.../rust/compile/torture/tuple_struct_unit.rs | 11 +++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/torture/tuple_struct_unit.rs
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index b4f264e0261..dfac00e3dbc 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 00000000000..cda19d2af0b
--- /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
+}
--
2.31.1
next prev parent reply other threads:[~2021-06-23 16:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 22:51 Mark Wielaard
2021-06-23 9:47 ` Philip Herron
2021-06-23 9:55 ` Philip Herron
2021-06-23 16:06 ` Mark Wielaard [this message]
2021-06-23 16:26 ` Philip Herron
2021-06-23 20:15 ` Mark Wielaard
2021-06-24 10:22 ` Philip Herron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fcc70f22cf4f37a150da061aa90219cd1d69a97c.camel@klomp.org \
--to=mark@klomp.org \
--cc=gcc-rust@gcc.gnu.org \
--cc=philip.herron@embecosm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).