Skip to content

Commit

Permalink
Lift T: Sized bounds from some strict_provenance NonNull methods
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Nov 7, 2022
1 parent 1f34e11 commit 662f1f2
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,7 @@ impl<T: ?Sized> NonNull<T> {
#[must_use]
#[inline]
#[unstable(feature = "strict_provenance", issue = "95228")]
pub fn addr(self) -> NonZeroUsize
where
T: Sized,
{
pub fn addr(self) -> NonZeroUsize {
// SAFETY: The pointer is guaranteed by the type to be non-null,
// meaning that the address will be non-zero.
unsafe { NonZeroUsize::new_unchecked(self.pointer.addr()) }
Expand All @@ -286,10 +283,7 @@ impl<T: ?Sized> NonNull<T> {
#[must_use]
#[inline]
#[unstable(feature = "strict_provenance", issue = "95228")]
pub fn with_addr(self, addr: NonZeroUsize) -> Self
where
T: Sized,
{
pub fn with_addr(self, addr: NonZeroUsize) -> Self {
// SAFETY: The result of `ptr::from::with_addr` is non-null because `addr` is guaranteed to be non-zero.
unsafe { NonNull::new_unchecked(self.pointer.with_addr(addr.get()) as *mut _) }
}
Expand All @@ -303,10 +297,7 @@ impl<T: ?Sized> NonNull<T> {
#[must_use]
#[inline]
#[unstable(feature = "strict_provenance", issue = "95228")]
pub fn map_addr(self, f: impl FnOnce(NonZeroUsize) -> NonZeroUsize) -> Self
where
T: Sized,
{
pub fn map_addr(self, f: impl FnOnce(NonZeroUsize) -> NonZeroUsize) -> Self {
self.with_addr(f(self.addr()))
}

Expand Down

0 comments on commit 662f1f2

Please sign in to comment.