Remove ptr-int transmute by converting UnsafeWeakPointer from usize to *mut T #127
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.
This transmute from a
Weak<T>
to ausize
is shockingly common in both the ecosystem and the standard library. It's doubly bad becauseWeak<T>
is arepr(Rust)
type, so without manually inspecting its layout at runtime it is a mistake to assume it has any particular layout. But primarily, this is a round-trip of a pointer through an integer type via transmute, and it's pretty clear Rust cannot have a sound memory model that permits these alongside the usual suite of compiler optimizations (casts are different, they're annoying but possible to support).If you're looking for other examples of this approach,
rayon
does a very similar thing to get pointers between threads: https://github.com/rayon-rs/rayon/blob/5b6adbbf5c6944ec42b54530820ee8c0ad0e35a9/src/lib.rs#L123-L147