Skip to content

Commit 1f34e11

Browse files
committed
Lift T: Sized bounds from some strict_provenance pointer methods
1 parent 44fcfb0 commit 1f34e11

File tree

2 files changed

+12
-36
lines changed

2 files changed

+12
-36
lines changed

library/core/src/ptr/const_ptr.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,11 @@ impl<T: ?Sized> *const T {
178178
#[must_use]
179179
#[inline]
180180
#[unstable(feature = "strict_provenance", issue = "95228")]
181-
pub fn addr(self) -> usize
182-
where
183-
T: Sized,
184-
{
181+
pub fn addr(self) -> usize {
185182
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
186183
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
187184
// provenance).
188-
unsafe { mem::transmute(self) }
185+
unsafe { mem::transmute(self.cast::<()>()) }
189186
}
190187

191188
/// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future
@@ -215,12 +212,9 @@ impl<T: ?Sized> *const T {
215212
#[must_use]
216213
#[inline]
217214
#[unstable(feature = "strict_provenance", issue = "95228")]
218-
pub fn expose_addr(self) -> usize
219-
where
220-
T: Sized,
221-
{
215+
pub fn expose_addr(self) -> usize {
222216
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
223-
self as usize
217+
self.cast::<()>() as usize
224218
}
225219

226220
/// Creates a new pointer with the given address.
@@ -238,10 +232,7 @@ impl<T: ?Sized> *const T {
238232
#[must_use]
239233
#[inline]
240234
#[unstable(feature = "strict_provenance", issue = "95228")]
241-
pub fn with_addr(self, addr: usize) -> Self
242-
where
243-
T: Sized,
244-
{
235+
pub fn with_addr(self, addr: usize) -> Self {
245236
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
246237
//
247238
// In the mean-time, this operation is defined to be "as if" it was
@@ -264,10 +255,7 @@ impl<T: ?Sized> *const T {
264255
#[must_use]
265256
#[inline]
266257
#[unstable(feature = "strict_provenance", issue = "95228")]
267-
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self
268-
where
269-
T: Sized,
270-
{
258+
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self {
271259
self.with_addr(f(self.addr()))
272260
}
273261

library/core/src/ptr/mut_ptr.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,11 @@ impl<T: ?Sized> *mut T {
188188
#[must_use]
189189
#[inline]
190190
#[unstable(feature = "strict_provenance", issue = "95228")]
191-
pub fn addr(self) -> usize
192-
where
193-
T: Sized,
194-
{
191+
pub fn addr(self) -> usize {
195192
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
196193
// SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
197194
// provenance).
198-
unsafe { mem::transmute(self) }
195+
unsafe { mem::transmute(self.cast::<()>()) }
199196
}
200197

201198
/// Gets the "address" portion of the pointer, and 'exposes' the "provenance" part for future
@@ -225,12 +222,9 @@ impl<T: ?Sized> *mut T {
225222
#[must_use]
226223
#[inline]
227224
#[unstable(feature = "strict_provenance", issue = "95228")]
228-
pub fn expose_addr(self) -> usize
229-
where
230-
T: Sized,
231-
{
225+
pub fn expose_addr(self) -> usize {
232226
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
233-
self as usize
227+
self.cast::<()>() as usize
234228
}
235229

236230
/// Creates a new pointer with the given address.
@@ -248,10 +242,7 @@ impl<T: ?Sized> *mut T {
248242
#[must_use]
249243
#[inline]
250244
#[unstable(feature = "strict_provenance", issue = "95228")]
251-
pub fn with_addr(self, addr: usize) -> Self
252-
where
253-
T: Sized,
254-
{
245+
pub fn with_addr(self, addr: usize) -> Self {
255246
// FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
256247
//
257248
// In the mean-time, this operation is defined to be "as if" it was
@@ -274,10 +265,7 @@ impl<T: ?Sized> *mut T {
274265
#[must_use]
275266
#[inline]
276267
#[unstable(feature = "strict_provenance", issue = "95228")]
277-
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self
278-
where
279-
T: Sized,
280-
{
268+
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self {
281269
self.with_addr(f(self.addr()))
282270
}
283271

0 commit comments

Comments
 (0)