public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
From: Philip Herron <philip.herron@embecosm.com>
To: gcc-rust@gcc.gnu.org
Subject: Re: tuple indexes
Date: Thu, 24 Jun 2021 11:22:16 +0100	[thread overview]
Message-ID: <242b4b89-eab2-eb3d-b440-bb58130f3e9d@embecosm.com> (raw)
In-Reply-To: <YNOWaOGn5DS2DMlW@wildebeest.org>


[-- Attachment #1.1: Type: text/plain, Size: 3366 bytes --]

On 23/06/2021 21:15, Mark Wielaard wrote:
> On Wed, Jun 23, 2021 at 12:51:34AM +0200, Mark Wielaard wrote:
>> Finally, the The Rust Reference says "A tuple index is used to refer
>> to the fields of tuples, tuple structs, and tuple variants." I don't
>> understand how this would work for tuple variants. Does anybody have
>> an example of how to refer to a tuple variant so a tuple index can be
>> used on it?
> Tom pointed out on irc that it doesn't seem possible to access enum
> variant types except through a matching expression. The Rust Reference
> also seems to be inconsistent. As mentioned above it mentions you can
> use a tuple index to refer to a field of a enum tuple variant. But it
> also says "A tuple indexing expression accesses fields of tuples and
> tuple structs." So it probably really isn't possible to use a tuple
> index on enum tuple variants.
>
> I did notice the same issue as for unit tuple struct types. The empty
> tuple wasn't accepted in the parser. The attached patch, also at
> https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=tuple_enum_variant_unit
> fixes this.
>
> It does include a test case, but most of it is commented out because
> actually resolving enum types isn't implemented yet. If you uncomment
> the rest of the testcase you get:
>
> tuple_enum_variants.rs:3:31: error: failed to resolve TypePath: E
>     3 | fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
>       |                               ^
> tuple_enum_variants.rs:3:31: error: unresolved type
> tuple_enum_variants.rs:3:33: error: failed to resolve TypePath: E
>     3 | fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
>       |                                 ^
> tuple_enum_variants.rs:3:33: error: unresolved type
> tuple_enum_variants.rs:3:35: error: failed to resolve TypePath: E
>     3 | fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
>       |                                   ^
> tuple_enum_variants.rs:3:35: error: unresolved type
> tuple_enum_variants.rs:3:10: error: failed to resolve TypePath: E
>     3 | fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
>       |          ^
> tuple_enum_variants.rs:3:10: error: unresolved type
> tuple_enum_variants.rs:3:17: error: failed to resolve TypePath: E
>     3 | fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
>       |                 ^
> tuple_enum_variants.rs:3:17: error: unresolved type
> tuple_enum_variants.rs:3:24: error: failed to resolve TypePath: E
>     3 | fn f(e0: E, e1: E, e2: E) -> (E,E,E,())
>       |                        ^
> tuple_enum_variants.rs:3:24: error: unresolved type
> tuple_enum_variants.rs:13:12: error: unknown root segment in path E::T0 lookup E
>    13 |   let e0 = E::T0();
>       |            ^
> tuple_enum_variants.rs:14:12: error: unknown root segment in path E::T1 lookup E
>    14 |   let e1 = E::T1(0);
>       |            ^
> tuple_enum_variants.rs:15:12: error: unknown root segment in path E::T2 lookup E
>    15 |   let e2 = E::T2(0,1);
>       |            ^
>
> Cheers,
>
> Mark
>
Hi Mark,

Thanks for the patch, its being merged:
https://github.com/Rust-GCC/gccrs/pull/522

I have open issues about enums and unions they will be fixed as part of
my work into traits. They are a type of algebraic data type so in theory
i can reuse a lot of the existing code to implement them.

Thanks

--Phil



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 665 bytes --]

      reply	other threads:[~2021-06-24 10:22 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
2021-06-23 16:26       ` Philip Herron
2021-06-23 20:15 ` Mark Wielaard
2021-06-24 10:22   ` Philip Herron [this message]

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=242b4b89-eab2-eb3d-b440-bb58130f3e9d@embecosm.com \
    --to=philip.herron@embecosm.com \
    --cc=gcc-rust@gcc.gnu.org \
    /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).