-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Rustdoc: size layout should show "uninhabited" for empty enums, not 0 #87008
Comments
I'm ambivalent, I don't think showing zero is necessarily wrong, especially since that's what's reported by |
In my opinion, I think that while size 0 is not wrong, that showing that it's uninhabited is more right, or at least more clear and makes the distinction. |
I don't understand uninhabited when I first see it. It is a hard word compared to 0. I think 0 is easier. Why not both? What if we show Also, what if the enum is not empty but have a single/multiple ZST like phantom type? |
I think displaying 0 is better as well, but we can do as @pickfire suggested and simply display both. |
0 is wrong. 0 means "this is a zero sized type", like
Ok, then we can link to some docs. I didn't see anything in the nomicon but I'm sure they'd take a PR adding it to "exotically sized types". |
This is a bug imo, it allows transmuting from ZSTs to uninhabited types which is UB. |
Even if they cannot be created, their size remain 0 as they don't "exist", however since they cannot be constructed, it makes sense to mention they're unhabited types. Well, I don't have a strong conviction on this in any case. I think we all agree for the mention of "unhabited" though. |
Yeah, that solved the issue of 0 which is wrong. I do think it is better to link it to https://doc.rust-lang.org/stable/reference/glossary.html?highlight=uninhabited#uninhabited, but I think it's wrong to put that in "size" such that it should be in "type" instead, because it doesn't have a size to begin with. Well, there are parts where rust sacrificed correctness for ease of understanding, one example is |
@rustbot claim |
Note that uninhabited is orthogonal to size. You can have an uninhabited type of any size. So I think showing uninhabitedness is good, but in addition to the size+align, not instead. |
Hmm, I think that |
That would surprise me, since that'd be different from what |
…ed, r=GuillaumeGomez rustdoc: Note in a type's layout/size if it is uninhabited Closes rust-lang#87008 ![image](https://user-images.githubusercontent.com/13556931/222900244-8e326d51-8d3b-4700-a935-96830179e2e9.png)
Originally posted by @jyn514 in #86263 (comment)
The text was updated successfully, but these errors were encountered: