-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking Issue for ptr_from_ref #106116
Comments
add ptr::from_{ref,mut} We have methods to avoid almost all `as` casts around raw pointer handling, except for the initial cast from reference to raw pointer. These new methods close that gap. (I also moved `null_mut` next to `null` to keep the file consistently organized.) r? libs-api Tracking issue: rust-lang#106116
for context of where these may be relevant, see also the discussion in rust-lang/book#3305 |
add ptr::from_{ref,mut} We have methods to avoid almost all `as` casts around raw pointer handling, except for the initial cast from reference to raw pointer. These new methods close that gap. (I also moved `null_mut` next to `null` to keep the file consistently organized.) r? libs-api Tracking issue: rust-lang/rust#106116
Filed an issue for a clippy lint: rust-lang/rust-clippy#10130 |
Pondering based on https://users.rust-lang.org/t/best-way-to-cast-option-t-to-const-t/88402?u=scottmcm: Should this perhaps take There's |
Is there a way to make it accept an |
You would need a way to create wide null pointers to convert from a generic Probably that's desired functionality for pub const fn null<T>() -> *const T
where
T: Pointee + ?Sized,
<T as Pointee>::Metadata: MetadataForNull, for some sealed trait the compiler automatically implements for all Or a new public trait Alternatively, the safety invariant for |
I usually think that having I think methods that treat null specially should be working on |
It seems to me that these functions could trivially be made |
@Raekye Seems entirely reasonable; send a PR! |
Make ptr::from_ref and ptr::from_mut in rust-lang#106116 const. As per rust-lang#106116 (comment)
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#108879 (Unconstrained terms should account for infer vars being equated) - rust-lang#108936 (Rustdoc: don't hide anonymous reexport) - rust-lang#108940 (Add myself to compiler reviewers list) - rust-lang#108945 (Make some report and emit errors take DefIds instead of BodyIds) - rust-lang#108946 (Document the resulting values produced when using `From<bool>` on floats) - rust-lang#108956 (Make ptr::from_ref and ptr::from_mut in rust-lang#106116 const.) - rust-lang#108960 (Remove `body_def_id` from `Inherited`) - rust-lang#108963 (only call git on git checkouts during bootstrap) - rust-lang#108964 (Fix the docs for pointer method with_metadata_of) Failed merges: - rust-lang#108950 (Directly construct Inherited in typeck.) r? `@ghost` `@rustbot` modify labels: rollup
add ptr::from_{ref,mut} We have methods to avoid almost all `as` casts around raw pointer handling, except for the initial cast from reference to raw pointer. These new methods close that gap. (I also moved `null_mut` next to `null` to keep the file consistently organized.) r? libs-api Tracking issue: rust-lang/rust#106116
Make ptr::from_ref and ptr::from_mut in #106116 const. As per rust-lang/rust#106116 (comment)
Pondering: Is there anything that we should do with these to help people from accidentally using That seems like the kind of mistake that you could make but not notice for a long time if you're just running normal binaries rather than MIRI. |
We could have a lint for that situation (any time a mutable ref is passed to |
What's the status here? Is this just waiting for someone to start stabilization process? Do we need more lints? Is something else missing? |
I think that. |
…dtolnay Stabilize `ptr::{from_ref, from_mut}` I propose to stabilize the following APIs: ```rust // mod core::ptr pub const fn from_ref<T: ?Sized>(r: &T) -> *const T; pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T; ``` Tracking issue: rust-lang#106116 --- `@RalfJung` what do you think we should do with `from_mut`? Stabilize it as const, given that you can't call it anyway (no way to get `&mut` in `const fn`)? Defer stabilizing it as const leaving the same issue/feature? Change issue/feature? Change issue/feature to the "`&mut` in const fn" one?
…dtolnay Stabilize `ptr::{from_ref, from_mut}` I propose to stabilize the following APIs: ```rust // mod core::ptr pub const fn from_ref<T: ?Sized>(r: &T) -> *const T; pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T; ``` Tracking issue: rust-lang#106116 --- ``@RalfJung`` what do you think we should do with `from_mut`? Stabilize it as const, given that you can't call it anyway (no way to get `&mut` in `const fn`)? Defer stabilizing it as const leaving the same issue/feature? Change issue/feature? Change issue/feature to the "`&mut` in const fn" one?
Rollup merge of rust-lang#117824 - WaffleLapkin:ptr_from_ref_stab, r=dtolnay Stabilize `ptr::{from_ref, from_mut}` I propose to stabilize the following APIs: ```rust // mod core::ptr pub const fn from_ref<T: ?Sized>(r: &T) -> *const T; pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T; ``` Tracking issue: rust-lang#106116 --- ``@RalfJung`` what do you think we should do with `from_mut`? Stabilize it as const, given that you can't call it anyway (no way to get `&mut` in `const fn`)? Defer stabilizing it as const leaving the same issue/feature? Change issue/feature? Change issue/feature to the "`&mut` in const fn" one?
As #117824 has been merged, this should be closed. |
Feature gate:
#![feature(ptr_from_ref)]
This is a tracking issue for
ptr::from_{ref,mut}
: methods to turn references into raw pointers without usingas
casts. We have methods to avoid almost all as casts around raw pointer handling, except for the initial cast from reference to raw pointer. These new methods close that gap. They also ensure that the pointee typeT
remains the same, without one having to repeat that type for the cast.Public API
Steps / History
Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: