Skip to content

Commit

Permalink
Unrolled build for rust-lang#122800
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#122800 - zachs18:nonnull-slice-is_empty, r=Amanieu

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

As per rust-lang#71146 (comment)

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

r? ```@Amanieu```
  • Loading branch information
rust-timer authored Mar 22, 2024
2 parents eff958c + 1b95760 commit f01126d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f01126d

Please sign in to comment.