public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marc <dkm@kataplop.net>
To: Mark Wielaard <mark@klomp.org>
Cc: Marc <dkm@kataplop.net>,  gcc-rust@gcc.gnu.org
Subject: Re: [PATCH] Suppress warning in rust-ast-lower-type.h ASTLowerGenericParam.visit.
Date: Tue, 29 Jun 2021 08:28:51 +0200	[thread overview]
Message-ID: <87lf6t2nh8.fsf@arrakis.kataplop.net> (raw)
In-Reply-To: <YNpeN7Gz5RYXiNK8@wildebeest.org> (Mark Wielaard's message of "Tue, 29 Jun 2021 01:41:43 +0200")

Mark Wielaard <mark@klomp.org> writes:

> On Tue, Jun 29, 2021 at 12:47:07AM +0200, Mark Wielaard wrote:
>> On Tue, Jun 29, 2021 at 12:06:56AM +0200, Marc wrote:
>> > Hi,
>> > 
>> > > Translating the AST LifetimeType to the HIR LifetimeType causes a warning:
>> > > warning: ‘ltt’ may be used uninitialized
>> > 
>> > Was wondering why this is needed as the switch case covers all enum
>> > variants, how can ltt be uninitialized ? I have the same fix locally but
>> > was thinking something else was causing the error...
>> 
>> LifetimeType is a plain enum, which aren't really their own types,
>> they are really just ints with fancy names. We could make them enum
>> class, which is a strong type. Then the compiler would know the switch
>> really covers all enum (class) variants. But then we have to provide
>> the right scope/type everywhere we use them in the code (which might
>> be a good idea, but is more typing).
>
> I just tried to make LifetimeType an enum class and that doesn't help.
> So I was wrong. I don't know why the compiler doesn't see this? It
> should know since if not all switch cases were covered, -Wswitch
> (enabled by -Wall) gives us a warning... So, I don't fully understand
> why gcc needs the default gcc_unreachable case. It is what is used in
> the rest of the code though.

I thought maybe that's a C++ vs C diff, or something caused by the
Lifetime being returned by a function call, but I can't reproduce it, so
that must be something else:

https://godbolt.org/z/sjbcWEqdj

Anyway, Philipp wants to have these enum shared between AST and HIR, so
this kind of 'if(AST::Foo) t=HIR::Foo' can be removed.

I'm still curious about why the warning is raised in this case...

Marc

  reply	other threads:[~2021-06-29  6:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 21:41 Mark Wielaard
2021-06-28 22:06 ` Marc
2021-06-28 22:47   ` Mark Wielaard
2021-06-28 23:41     ` Mark Wielaard
2021-06-29  6:28       ` Marc [this message]
2021-06-29  9:10         ` Mark Wielaard

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=87lf6t2nh8.fsf@arrakis.kataplop.net \
    --to=dkm@kataplop.net \
    --cc=gcc-rust@gcc.gnu.org \
    --cc=mark@klomp.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).