From 90722811c8818b1ce4c7819dac41f22837fa98c6 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 1 Apr 2022 18:51:57 -0700 Subject: [PATCH 1/4] Deprecate the `ptr_to_from_bits` feature The strict provenance APIs are a better version of these, and things like `.addr()` work for the "that cast looks sketchy" case even if the full strict provenance stuff never happens. So I think it's fine to move away from these, and encourage the others instead. --- library/core/src/ptr/const_ptr.rs | 5 +++++ library/core/src/ptr/mut_ptr.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index af64fbc8e9eca..e460a7f3b1e3e 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -119,6 +119,7 @@ impl *const T { /// assert_eq!(p1.to_bits() - p0.to_bits(), 4); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] + #[rustc_deprecated(since = "1.62", reason = "replaced by the `addr` method")] pub fn to_bits(self) -> usize where T: Sized, @@ -140,6 +141,10 @@ impl *const T { /// assert_eq!(<*const u8>::from_bits(1), dangling); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] + #[rustc_deprecated( + since = "1.62", + reason = "replaced by the `with_addr` method or the `ptr::invalid` function" + )] #[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 d6872ba1c20f0..351012e6ffc8f 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -125,6 +125,7 @@ impl *mut T { /// assert_eq!(p1.to_bits() - p0.to_bits(), 4); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] + #[rustc_deprecated(since = "1.62", reason = "replaced by the `addr` method")] pub fn to_bits(self) -> usize where T: Sized, @@ -146,6 +147,10 @@ impl *mut T { /// assert_eq!(<*mut u8>::from_bits(1), dangling); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] + #[rustc_deprecated( + since = "1.62", + reason = "replaced by the `with_addr` method or the `ptr::invalid_mut` function" + )] #[allow(fuzzy_provenance_casts)] // this is an unstable and semi-deprecated cast function pub fn from_bits(bits: usize) -> Self where From 4d37d1f4226bd92bf6c129977357afd50993cf0a Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 3 Apr 2022 13:19:30 -0700 Subject: [PATCH 2/4] Refer to the `exposed` versions of the methods instead Changing to those doesn't introduce any new unsoundness over the existing ones, so they're the better "if you won't want to think about it" replacement. But also mention the strict provenance APIs, as that's what we'd rather they use instead. --- library/core/src/ptr/const_ptr.rs | 9 +++++++-- library/core/src/ptr/mut_ptr.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index e460a7f3b1e3e..2c371f635ab97 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -119,7 +119,11 @@ impl *const T { /// assert_eq!(p1.to_bits() - p0.to_bits(), 4); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] - #[rustc_deprecated(since = "1.62", reason = "replaced by the `addr` method")] + #[rustc_deprecated( + since = "1.62", + reason = "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, @@ -143,7 +147,8 @@ impl *const T { #[unstable(feature = "ptr_to_from_bits", issue = "91126")] #[rustc_deprecated( since = "1.62", - reason = "replaced by the `with_addr` method or the `ptr::invalid` function" + reason = "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 diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 351012e6ffc8f..7968253156237 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -125,7 +125,11 @@ impl *mut T { /// assert_eq!(p1.to_bits() - p0.to_bits(), 4); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] - #[rustc_deprecated(since = "1.62", reason = "replaced by the `addr` method")] + #[rustc_deprecated( + since = "1.62", + reason = "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, @@ -149,7 +153,8 @@ impl *mut T { #[unstable(feature = "ptr_to_from_bits", issue = "91126")] #[rustc_deprecated( since = "1.62", - reason = "replaced by the `with_addr` method or the `ptr::invalid_mut` function" + reason = "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 From a9e92be1f98605f343dfc6684107e236e6606947 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 21 Nov 2022 15:10:59 -0800 Subject: [PATCH 3/4] Bump ptr_to_from_bits deprecation to Rust 1.67 --- library/core/src/ptr/const_ptr.rs | 4 ++-- library/core/src/ptr/mut_ptr.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 2c371f635ab97..e966e1bb46687 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -120,7 +120,7 @@ impl *const T { /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] #[rustc_deprecated( - since = "1.62", + since = "1.67", reason = "replaced by the `exposed_addr` method, or update your code \ to follow the strict provenance rules using its APIs" )] @@ -146,7 +146,7 @@ impl *const T { /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] #[rustc_deprecated( - since = "1.62", + since = "1.67", reason = "replaced by the `ptr::from_exposed_addr` function, or update \ your code to follow the strict provenance rules using its APIs" )] diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 7968253156237..9507e8430c78f 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -126,7 +126,7 @@ impl *mut T { /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] #[rustc_deprecated( - since = "1.62", + since = "1.67", reason = "replaced by the `exposed_addr` method, or update your code \ to follow the strict provenance rules using its APIs" )] @@ -152,7 +152,7 @@ impl *mut T { /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] #[rustc_deprecated( - since = "1.62", + since = "1.67", reason = "replaced by the `ptr::from_exposed_addr_mut` function, or \ update your code to follow the strict provenance rules using its APIs" )] From 6d943af735a86cd7f77305b5723b9481d9bf1f71 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 21 Nov 2022 15:18:36 -0800 Subject: [PATCH 4/4] Rustc_deprecated attribute superseded by deprecated --- library/core/src/ptr/const_ptr.rs | 8 ++++---- library/core/src/ptr/mut_ptr.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index e966e1bb46687..969029e262e02 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -119,9 +119,9 @@ impl *const T { /// assert_eq!(p1.to_bits() - p0.to_bits(), 4); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] - #[rustc_deprecated( + #[deprecated( since = "1.67", - reason = "replaced by the `exposed_addr` method, or update your code \ + 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 @@ -145,9 +145,9 @@ impl *const T { /// assert_eq!(<*const u8>::from_bits(1), dangling); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] - #[rustc_deprecated( + #[deprecated( since = "1.67", - reason = "replaced by the `ptr::from_exposed_addr` function, or update \ + 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 diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 9507e8430c78f..d1b3a63443379 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -125,9 +125,9 @@ impl *mut T { /// assert_eq!(p1.to_bits() - p0.to_bits(), 4); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] - #[rustc_deprecated( + #[deprecated( since = "1.67", - reason = "replaced by the `exposed_addr` method, or update your code \ + 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 @@ -151,9 +151,9 @@ impl *mut T { /// assert_eq!(<*mut u8>::from_bits(1), dangling); /// ``` #[unstable(feature = "ptr_to_from_bits", issue = "91126")] - #[rustc_deprecated( + #[deprecated( since = "1.67", - reason = "replaced by the `ptr::from_exposed_addr_mut` function, or \ + 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