]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #103702 - WaffleLapkin:lift-sized-bounds-from-pointer-methods-where...
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Wed, 18 Jan 2023 10:25:36 +0000 (15:55 +0530)
committerGitHub <noreply@github.com>
Wed, 18 Jan 2023 10:25:36 +0000 (15:55 +0530)
Lift `T: Sized` bounds from some `strict_provenance` pointer methods

This PR removes requirement for `T` (pointee type) to be `Sized` to call `pointer::{addr, expose_addr, with_addr, map_addr}`. These functions don't use `T`'s size, so there is no reason for them to require this. Updated public API:

cc ``@Gankra,`` #95228
r? libs-api

1  2 
library/core/src/ptr/const_ptr.rs
library/core/src/ptr/mut_ptr.rs
library/core/src/ptr/non_null.rs

index 0a74c03d70f3a6cf17c95e9a059d49f2960f0945,49831dbe44bc29cb890b0560e2d01cdc5c0db7d2..7b1cb5488bcac650871b9ee38de84fb536bef4e7
@@@ -200,12 -176,9 +200,9 @@@ impl<T: ?Sized> *const T 
      /// might change in the future (including possibly weakening this so it becomes wholly
      /// equivalent to `self as usize`). See the [module documentation][crate::ptr] for details.
      #[must_use]
 -    #[inline]
 +    #[inline(always)]
      #[unstable(feature = "strict_provenance", issue = "95228")]
-     pub fn addr(self) -> usize
-     where
-         T: Sized,
-     {
+     pub fn addr(self) -> usize {
          // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
          // SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
          // provenance).
      ///
      /// [`from_exposed_addr`]: from_exposed_addr
      #[must_use]
 -    #[inline]
 +    #[inline(always)]
      #[unstable(feature = "strict_provenance", issue = "95228")]
-     pub fn expose_addr(self) -> usize
-     where
-         T: Sized,
-     {
+     pub fn expose_addr(self) -> usize {
          // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
-         self as usize
+         self.cast::<()>() as usize
      }
  
      /// Creates a new pointer with the given address.
index d70fb70c79fa4dc6dacc84297e67a062235bd8d8,578e27fec7a06c874afeac643956e965c3d19809..ed1e3bd48122761607f22a10f0bfb11608c0d892
@@@ -206,12 -186,9 +206,9 @@@ impl<T: ?Sized> *mut T 
      /// might change in the future (including possibly weakening this so it becomes wholly
      /// equivalent to `self as usize`). See the [module documentation][crate::ptr] for details.
      #[must_use]
 -    #[inline]
 +    #[inline(always)]
      #[unstable(feature = "strict_provenance", issue = "95228")]
-     pub fn addr(self) -> usize
-     where
-         T: Sized,
-     {
+     pub fn addr(self) -> usize {
          // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
          // SAFETY: Pointer-to-integer transmutes are valid (if you are okay with losing the
          // provenance).
      ///
      /// [`from_exposed_addr_mut`]: from_exposed_addr_mut
      #[must_use]
 -    #[inline]
 +    #[inline(always)]
      #[unstable(feature = "strict_provenance", issue = "95228")]
-     pub fn expose_addr(self) -> usize
-     where
-         T: Sized,
-     {
+     pub fn expose_addr(self) -> usize {
          // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
-         self as usize
+         self.cast::<()>() as usize
      }
  
      /// Creates a new pointer with the given address.
Simple merge