Skip to content

Commit 9072281

Browse files
committed
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.
1 parent b7bc90f commit 9072281

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

library/core/src/ptr/const_ptr.rs

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl<T: ?Sized> *const T {
119119
/// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
120120
/// ```
121121
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
122+
#[rustc_deprecated(since = "1.62", reason = "replaced by the `addr` method")]
122123
pub fn to_bits(self) -> usize
123124
where
124125
T: Sized,
@@ -140,6 +141,10 @@ impl<T: ?Sized> *const T {
140141
/// assert_eq!(<*const u8>::from_bits(1), dangling);
141142
/// ```
142143
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
144+
#[rustc_deprecated(
145+
since = "1.62",
146+
reason = "replaced by the `with_addr` method or the `ptr::invalid` function"
147+
)]
143148
#[allow(fuzzy_provenance_casts)] // this is an unstable and semi-deprecated cast function
144149
pub fn from_bits(bits: usize) -> Self
145150
where

library/core/src/ptr/mut_ptr.rs

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl<T: ?Sized> *mut T {
125125
/// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
126126
/// ```
127127
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
128+
#[rustc_deprecated(since = "1.62", reason = "replaced by the `addr` method")]
128129
pub fn to_bits(self) -> usize
129130
where
130131
T: Sized,
@@ -146,6 +147,10 @@ impl<T: ?Sized> *mut T {
146147
/// assert_eq!(<*mut u8>::from_bits(1), dangling);
147148
/// ```
148149
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
150+
#[rustc_deprecated(
151+
since = "1.62",
152+
reason = "replaced by the `with_addr` method or the `ptr::invalid_mut` function"
153+
)]
149154
#[allow(fuzzy_provenance_casts)] // this is an unstable and semi-deprecated cast function
150155
pub fn from_bits(bits: usize) -> Self
151156
where

0 commit comments

Comments
 (0)