Stream: t-compiler/const-eval

Topic: unreachable-discriminant


RalfJ (Oct 17 2018 at 08:18, on Zulip):

@Oli so about https://github.com/rust-lang/rust/pull/55142...

RalfJ (Oct 17 2018 at 08:19, on Zulip):

I can make this into a bug! if you want. Not sure why we'd want an ICE there but well^^

RalfJ (Oct 17 2018 at 08:19, on Zulip):

Looking at https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=e75c6dc3f500490e032fff4266bd8682, it seems that even before @varkor's patch, we don't actually get a GetDiscriminant for empty enums

oli (Oct 17 2018 at 08:20, on Zulip):

Well. I don't think it's an ICE. It is literally unreachable code.

RalfJ (Oct 17 2018 at 08:20, on Zulip):

though I think with the changes around ! patterns that @nikomatsakis and I have been planning, that might change

RalfJ (Oct 17 2018 at 08:20, on Zulip):

I agree it is likely unreachable currently, but that is an artifact of how we generate MIR

RalfJ (Oct 17 2018 at 08:20, on Zulip):

and there is perfectly reasonable MIR that reaches this

RalfJ (Oct 17 2018 at 08:20, on Zulip):

just rustc never produces it

oli (Oct 17 2018 at 08:20, on Zulip):

You'd still need to be able to create a value of uninhabited type to get here

RalfJ (Oct 17 2018 at 08:20, on Zulip):

but I think we should produce it

RalfJ (Oct 17 2018 at 08:21, on Zulip):

true, but without validation that's not hard

oli (Oct 17 2018 at 08:21, on Zulip):

won't we error out before even getting here?

RalfJ (Oct 17 2018 at 08:21, on Zulip):

only through validation

RalfJ (Oct 17 2018 at 08:21, on Zulip):

I hope

RalfJ (Oct 17 2018 at 08:21, on Zulip):

this is another instance of my pet peeve: enums with 0 variants are not special

RalfJ (Oct 17 2018 at 08:21, on Zulip):

just the "is this a valid discriminant" check cannot succeed

RalfJ (Oct 17 2018 at 08:22, on Zulip):

but it doesnt have to fail any other way than a bad discriminant for a 5-variant enum does

oli (Oct 17 2018 at 08:22, on Zulip):

ok. I remember we used to have some code about erroring out when encountering uninhabited locals

RalfJ (Oct 17 2018 at 08:22, on Zulip):

yeah we did, and we killed it, and I am happy about that

RalfJ (Oct 17 2018 at 08:22, on Zulip):

at least I couldnt find it any more^^

oli (Oct 17 2018 at 08:22, on Zulip):

ok, I agree that fewer special cases are good

oli (Oct 17 2018 at 08:22, on Zulip):

I'm just unhappy that we don't have a test case for this path

oli (Oct 17 2018 at 08:23, on Zulip):

which we can't have, since rustc just bails out

RalfJ (Oct 17 2018 at 08:23, on Zulip):

that's also a good way to put it, yes

RalfJ (Oct 17 2018 at 08:24, on Zulip):

yeah, well... that's https://github.com/solson/miri/issues/196

oli (Oct 17 2018 at 08:24, on Zulip):

lol the MIR of this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=fad502214672640ae55156215fa77f5c

RalfJ (Oct 17 2018 at 08:24, on Zulip):

brb, getting into the dead spot

RalfJ (Oct 17 2018 at 08:25, on Zulip):

lol the MIR of this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=fad502214672640ae55156215fa77f5c

yeah that makes lots of sense actually

RalfJ (Oct 17 2018 at 08:25, on Zulip):

match x { _ => ... } is equivalent to let _ = x; ...

RalfJ (Oct 17 2018 at 08:26, on Zulip):

it is not supposed to inspect the discriminant

RalfJ (Oct 17 2018 at 08:26, on Zulip):

so its not even UB, without validity

Last update: Nov 15 2019 at 21:30UTC