Skip to content

Commit f01126d

Browse files
authored
Unrolled build for rust-lang#122800
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```
2 parents eff958c + 1b95760 commit f01126d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

library/core/src/ptr/non_null.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,25 @@ impl<T> NonNull<[T]> {
15751575
self.as_ptr().len()
15761576
}
15771577

1578+
/// Returns `true` if the non-null raw slice has a length of 0.
1579+
///
1580+
/// # Examples
1581+
///
1582+
/// ```rust
1583+
/// #![feature(slice_ptr_is_empty_nonnull)]
1584+
/// use std::ptr::NonNull;
1585+
///
1586+
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
1587+
/// assert!(!slice.is_empty());
1588+
/// ```
1589+
#[unstable(feature = "slice_ptr_is_empty_nonnull", issue = "71146")]
1590+
#[rustc_const_unstable(feature = "const_slice_ptr_is_empty_nonnull", issue = "71146")]
1591+
#[must_use]
1592+
#[inline]
1593+
pub const fn is_empty(self) -> bool {
1594+
self.len() == 0
1595+
}
1596+
15781597
/// Returns a non-null pointer to the slice's buffer.
15791598
///
15801599
/// # Examples

0 commit comments

Comments
 (0)