-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty match expressions can be ill-typed. #24590
Comments
See the dialogue starting here in particular: #4499 (comment) Essentially, it is a huge abuse of the system to transmute a value to an instance of an empty enum. Arguably we should assign a size to an empty enum that would ensure such transmutation does not occur. (in the past I have considered e.g. changing our internal size representation for types to be an I am actually halfway tempted to assign them the size |
I don't actually think this is a bug - this code invokes undefined behavior in multiple ways, so it's ok that it segfaults. Operations on unreachable values are themselves unreachable; operations on |
@reem right, well, i guess my point is that it would make it more obvious that the user is doing something bad, in a way that ... shouldn't ... break anything else? |
@pnkfelix imo it's actually useful for these operations to be any type, since it simplifies writing code that deals with empty "values" in branches-never-taken. That said, you could deal with this in a lot of different ways, so it's not a big deal if it becomes an error. |
I would imagine changing the size of an empty enum would require an RFC, and as @reem says, this is okay to segfault, so I'm gonna give it a close. |
I've been playing around with empty match expressions, which are only allowed if the type being matched on is empty, and I've noticed that it's possible to compile (seemingly) ill-typed code like the following:
I would have expected this not to compile as
match *x {}
can only sensibly evaluate to()
, yety
has typeu32
. The compiler only reports that the variabley
is unused.Running it on Linux x86_64 results in a segfault followed by an illegal instruction.
Some solutions I see are:
()
.The text was updated successfully, but these errors were encountered: