From 4250216663331fc4efcbd4bb2e5f93caa1b4d2b8 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Wed, 20 Mar 2024 17:44:26 -0500 Subject: [PATCH 1/2] Add `NonNull::<[T]>::is_empty` as insta-stable. --- library/core/src/ptr/non_null.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 9c0236c172a93..8bb87734eb31f 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1575,6 +1575,27 @@ impl NonNull<[T]> { self.as_ptr().len() } + /// Returns `true` if the non-null raw slice has a length of 0. + /// + /// # Examples + /// + /// ```rust + /// use std::ptr::NonNull; + /// + /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3); + /// assert!(!slice.is_empty()); + /// ``` + #[stable(feature = "slice_ptr_is_empty_nonnull", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable( + feature = "const_slice_ptr_is_empty_nonnull", + since = "CURRENT_RUSTC_VERSION" + )] + #[must_use] + #[inline] + pub const fn is_empty(self) -> bool { + self.len() == 0 + } + /// Returns a non-null pointer to the slice's buffer. /// /// # Examples From 1b95760e41bed110ea20b44f85193fe900b13242 Mon Sep 17 00:00:00 2001 From: Zachary S Date: Thu, 21 Mar 2024 17:00:41 -0500 Subject: [PATCH 2/2] Not insta-stable --- library/core/src/ptr/non_null.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 8bb87734eb31f..2ac42e20d43b2 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1580,16 +1580,14 @@ impl NonNull<[T]> { /// # Examples /// /// ```rust + /// #![feature(slice_ptr_is_empty_nonnull)] /// use std::ptr::NonNull; /// /// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3); /// assert!(!slice.is_empty()); /// ``` - #[stable(feature = "slice_ptr_is_empty_nonnull", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable( - feature = "const_slice_ptr_is_empty_nonnull", - since = "CURRENT_RUSTC_VERSION" - )] + #[unstable(feature = "slice_ptr_is_empty_nonnull", issue = "71146")] + #[rustc_const_unstable(feature = "const_slice_ptr_is_empty_nonnull", issue = "71146")] #[must_use] #[inline] pub const fn is_empty(self) -> bool {