about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2022-11-22 01:26:05 -0500
committerGitHub <noreply@github.com>2022-11-22 01:26:05 -0500
commit81ea6105e2e230705e9ac4b7af57968504fe4e2c (patch)
treedf39d2d23387906d5e75e4adf7948378a495662f
parent1dd515f27393c7f1e8b57f9d21c183cd05005b5c (diff)
parent6d943af735a86cd7f77305b5723b9481d9bf1f71 (diff)
downloadrust-81ea6105e2e230705e9ac4b7af57968504fe4e2c.tar.gz
rust-81ea6105e2e230705e9ac4b7af57968504fe4e2c.zip
Rollup merge of #95583 - scottmcm:deprecate-ptr-to-from-bits, 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 (#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 #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
-rw-r--r--library/core/src/ptr/const_ptr.rs10
-rw-r--r--library/core/src/ptr/mut_ptr.rs10
2 files changed, 20 insertions, 0 deletions
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs
index af64fbc8e9e..969029e262e 100644
--- a/library/core/src/ptr/const_ptr.rs
+++ b/library/core/src/ptr/const_ptr.rs
@@ -119,6 +119,11 @@ impl<T: ?Sized> *const T {
     /// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
     /// ```
     #[unstable(feature = "ptr_to_from_bits", issue = "91126")]
+    #[deprecated(
+        since = "1.67",
+        note = "replaced by the `exposed_addr` method, or update your code \
+            to follow the strict provenance rules using its APIs"
+    )]
     pub fn to_bits(self) -> usize
     where
         T: Sized,
@@ -140,6 +145,11 @@ impl<T: ?Sized> *const T {
     /// assert_eq!(<*const u8>::from_bits(1), dangling);
     /// ```
     #[unstable(feature = "ptr_to_from_bits", issue = "91126")]
+    #[deprecated(
+        since = "1.67",
+        note = "replaced by the `ptr::from_exposed_addr` function, or update \
+            your code to follow the strict provenance rules using its APIs"
+    )]
     #[allow(fuzzy_provenance_casts)] // this is an unstable and semi-deprecated cast function
     pub fn from_bits(bits: usize) -> Self
     where
diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs
index d6872ba1c20..d1b3a634433 100644
--- a/library/core/src/ptr/mut_ptr.rs
+++ b/library/core/src/ptr/mut_ptr.rs
@@ -125,6 +125,11 @@ impl<T: ?Sized> *mut T {
     /// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
     /// ```
     #[unstable(feature = "ptr_to_from_bits", issue = "91126")]
+    #[deprecated(
+        since = "1.67",
+        note = "replaced by the `exposed_addr` method, or update your code \
+            to follow the strict provenance rules using its APIs"
+    )]
     pub fn to_bits(self) -> usize
     where
         T: Sized,
@@ -146,6 +151,11 @@ impl<T: ?Sized> *mut T {
     /// assert_eq!(<*mut u8>::from_bits(1), dangling);
     /// ```
     #[unstable(feature = "ptr_to_from_bits", issue = "91126")]
+    #[deprecated(
+        since = "1.67",
+        note = "replaced by the `ptr::from_exposed_addr_mut` function, or \
+            update your code to follow the strict provenance rules using its APIs"
+    )]
     #[allow(fuzzy_provenance_casts)] // this is an unstable and semi-deprecated cast function
     pub fn from_bits(bits: usize) -> Self
     where