Force tag to the same position in KStringInner #77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
tag()
relies onKStringInner
having a tag field at the same offset in every union variant, and every union variant isrepr(C)
so that this holds (provided thatB
has the same size, anyway -- since it's a sealed trait, that is guaranteed for any constructed instance, though it's a bit subtle).However, the union itself does not have a guaranteed layout unless one uses
repr(C)
. It's a bit silly, but technically every single variant could be in a different location, causing the tags not to line up within the union even though they do within the structs individually. See e.g. https://rust-lang.github.io/unsafe-code-guidelines/layout/unions.htmlThe fixes would be:
unsafe
implementation).I opted to do (2) as a quick fix to send out.
(Did not add tests, because I believe this has no change in behavior -- the layout is presumably the same now as it was before, only now it is guaranteed.)