-
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 feature(ptr_to_from_bits)
#91126
Comments
I'm not a fan of "as" casts in general :-] |
Add `<*{const|mut} T>::{to|from}_bits` Named based on the floating-point methods of the same name, as those are also about returning the *representation* of the value. Tracking issue: rust-lang#91126 Based on the conversation in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20methods.20as.20more.20specific.20versions.20of.20.60as.60/near/238391074 r? `@joshtriplett`
I do not believe these methods are the correct ones. In particular, I believe that stabilizing these methods would force Rust further down an incorrect evolutionary path regarding its story of pointers in general. |
Could we consider adding this to |
is this related to #95241 ? |
ptr_to_from_bits is inherently contradictory to the goals of the strict_provenance (#95228) experiment, yes. In my initial WIP PR I actually marked them as deprecated just to see what was using them. The problems are that they:
Strict provenance is experimenting with whether we can specify
Both of these are very desirable for more properly targetting CHERI. The APIs don't need to be deprecated but stabilization should maybe be held off on while we're experimenting in this space. |
@fbstj No, this came from a much less interesting place of wanting to be able to better lint typos like With https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.addr now available, I think this feature should just be deprecated. To be nice, though, we shouldn't remove this for another 5 weeks or so, to give unstable users an easier transition. EDIT: I opened #95583 to do that. |
…, r=dtolnay Deprecate the unstable `ptr_to_from_bits` feature I propose that we deprecate the (unstable!) `to_bits` and `from_bits` methods on raw pointers. (With the intent to ~~remove them once `addr` has been around long enough to make the transition easy on people -- maybe another 6 weeks~~ remove them fairly soon after, as the strict and expose versions have been around for a while already.) The APIs that came from the strict provenance explorations (rust-lang#95228) are a more holistic version of these, and things like `.expose_addr()` work for the "that cast looks sketchy" case even if the full strict provenance stuff never happens. (As a bonus, `addr` is even shorter than `to_bits`, though it is only applicable if people can use full strict provenance! `addr` is *not* a direct replacement for `to_bits`.) So I think it's fine to move away from the `{to|from}_bits` methods, and encourage the others instead. That also resolves the worry that was brought up (I forget where) that `q.to_bits()` and `(*q).to_bits()` both work if `q` is a pointer-to-floating-point, as they also have a `to_bits` method. Tracking issue rust-lang#91126 Code search: https://github.com/search?l=Rust&p=1&q=ptr_to_from_bits&type=Code For potential pushback, some users in case they want to chime in - `@RSSchermer` https://github.com/RSSchermer/ARWA/blob/365bb68541447453fc44f6fbcc5d394bb94c14e9/arwa/src/html/custom_element.rs#L105 - `@strax` https://github.com/strax/pbr/blob/99616d1dbf42f93ec8dd668d05b3180649558180/openexr/src/core/alloc.rs#L36 - `@MiSawa` https://github.com/MiSawa/pomelo/blob/577c6223588d539295a71ff125d8f249e59f4146/crates/kernel/src/timer.rs#L50
The 1 year anniversary of deprecating the |
Rollup merge of rust-lang#127071 - Sky9x:remove-ptr-to-from-bits, r=scottmcm Remove (deprecated & unstable) {to,from}_bits pointer methods These unstable methods have been deprecated for more than a year (since rust-lang#95583). Remove them. See rust-lang#91126 (comment) and https://github.com/rust-lang/rust/pull/110441/files#r1169574509. Closes rust-lang#91126. r? `@scottmcm`
Feature gate:
#![feature(ptr_to_from_bits)]
This is a tracking issue for
<*const T>::from_bits
,<*mut T>::from_bits
,<*const T>::to_bits
, and<*mut T>::to_bits
.These, like the stable
<*const T>::cast
and<*mut T>::cast
, is proposed as a method for one of the many specific things thatas
can do to help increase readability of which of those things is happening, as well as to be able to give better compilation errors (or lints) for suspicious code patterns that aren't necessarily wrong. (For example,p as u32
is legal but suspicious, as it's possible it was meant to be*p as u32
. By having the method,p.to_bits() as u32
is unambiguous.)See the conversation in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20methods.20as.20more.20specific.20versions.20of.20.60as.60/near/238391074
Public API
Steps / History
<*{const|mut} T>::{to|from}_bits
#91127Unresolved Questions
The text was updated successfully, but these errors were encountered: