Rollup merge of #122800 - zachs18:nonnull-slice-is_empty, r=Amanieu

Add `NonNull::<[T]>::is_empty`.

As per https://github.com/rust-lang/rust/issues/71146#issuecomment-2008373983

I figured this should be fine to be insta-stable (with an FCP), but I can edit if that is not desired.

r? ```@Amanieu```
This commit is contained in:
Matthias Krüger 2024-03-22 11:37:00 +01:00 committed by GitHub
commit ef4a64b5d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1575,6 +1575,25 @@ impl<T> NonNull<[T]> {
self.as_ptr().len()
}
/// Returns `true` if the non-null raw slice has a length of 0.
///
/// # 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());
/// ```
#[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 {
self.len() == 0
}
/// Returns a non-null pointer to the slice's buffer.
///
/// # Examples