-
Notifications
You must be signed in to change notification settings - Fork 105
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
Implement FromZeroes for thin raw pointers #294
Conversation
06a411b
to
a614f5f
Compare
Makes progress on #170
a614f5f
to
19f1bdc
Compare
/// The all-zeroes const and mut raw pointers are valid, and it is sound to | ||
/// materialize them from nothing. The existence of `ptr::null` [1] and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it clearly documented anywhere that 0
is a valid value for the null pointer? Infamously, the C standard does not require that null pointers have an all-zero bit-pattern, only that they compare as equal to 0
.
unsafe_impl!(T: Sized => FromZeroes for *const T); | ||
unsafe_impl!(T: Sized => FromZeroes for *mut T); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet from the internals of the standard library gives me pause:
pub const fn invalid<T>(addr: usize) -> *const T {
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
// We use transmute rather than a cast so tools like Miri can tell that this
// is *not* the same as from_exposed_addr.
// SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
// pointer).
unsafe { mem::transmute(addr) }
}
The use of mem::transmute
suggests that these sorts of transmutes are fine now, but what about the comment "I am magic and should be a compiler intrinsic"?
Current plan is to wait until this change (or something similar) lands so the soundness of this PR is clearly backed by the Rust reference. |
Closing in favor of #584. |
Makes progress on #170