-
Notifications
You must be signed in to change notification settings - Fork 21
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 from_{ref,mut} to eliminate casts to pointers #272
Conversation
@cagatay-y, |
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.
ptr_from_ref
is now stable. :)
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.
Let's replace all instances of ptr::from_ref(unsafe {&foo})
with ptr::addr_of!(foo)
.
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.
Same for replacing ptr::from_ref(unsafe {&mut foo})
with ptr::addr_of_mut!(foo)
.
Do you mean the ones inside a |
Yeah. While the amount of unsafe blocks stays the same in those cases, the amount of unsafe operations would be less. And it would be more consistent with the rest of the code. |
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.
Sorry for not catching this earlier, but can we also enable the corresponding lint?
https://rust-lang.github.io/rust-clippy/master/index.html#ref_as_ptr
I can't get the lint to work on my machine. It complains that no such lint exists. I am version on 0.1.77. Does it work for you? |
Ah, true. This will be in Rust 1.77.0, but the current stable is 1.76.0. |
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.
Thanks!
As it stands, the PR requires
ptr_from_ref
andstrict_provenance
to land in stable. If theptr_from_ref
lands first, the branch can be updated to make use of the polyfill for thepointer::addr
method in the sptr crate, as instructed in its documentation.