Skip to content
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

Use a union to avoid UB with uninitialized &mut T #6

Merged
merged 1 commit into from
Nov 27, 2018

Conversation

SimonSapin
Copy link
Contributor

The soundness rules of unsafe code are not completely settled in the language, but in some proposals creating &mut T with an uninitialized T value is Undefined Behavior even if nothing reads from that reference.

In a union with a zero-size variant however, being uninitialized is a valid state since the storage for that variant is entirely padding.

Bumping the version number because of the new T: Copy bound on Uninitialized, which is require because unions with non-Copy fields rust-lang/rust#32836 (or the MaybeUninit union itself rust-lang/rust#53491) are not stable in the language yet.

@maciejhirsz maciejhirsz merged commit 7b1c67f into ratel-rust:master Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants