-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add as_mut_ptr #25
base: master
Are you sure you want to change the base?
Add as_mut_ptr #25
Conversation
Fixes sfackler#24
I would rather fix the definition of Opaque, if that is actually incorrect. |
I'm not sure if it's even possible for the
A |
The definition of Opaque came from eddyb, who I trust to have an accurate understanding of the compiler's memory model (at least as of 2017 when it was designed). As I mentioned in #24, Rust's concept of mutability and C's concept of const-correctness do not align. The |
Memory model of Rust has changed since then, and is still not fully defined. However, unsafe fn not_allowed<T>(ptr: &UnsafeCell<T>) -> &mut T {
let t = ptr as *const UnsafeCell<T> as *mut T;
// This is undefined behavior, because the `*mut T` pointer
// was not obtained through `.get()` nor `.raw_get()`:
unsafe { &mut *t }
} |
"Is similar to" is not the same thing as "is". |
The point is that casting a pointer to an |
If we are operating under the belief that Opaque's structure was valid in 2017, I do not believe these concerns are realistic. This library is downloaded ~140,000 times a day. The Rust developers are not going to change the memory model and its implementation in the compiler in a way that will break foreign-types overnight. I would like to see either:
|
I traced that documentation comment back to this PR and this Zulip stream, in which there is talk about mostly disallowing this for now, but wanting to allow it in the future. Not sure what the conclusion here should be, just noting. |
Fixes #24