diff options
| author | bors <bors@rust-lang.org> | 2024-03-22 12:29:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-22 12:29:42 +0000 |
| commit | 1447f9d38ca388ca178a544534b3cff72945fa1e (patch) | |
| tree | 51b4cffdfe26ba21cda4793ce8dbe20d5f06c965 /library/core/src | |
| parent | eff958c59e8c07ba0515e164b825c9001b242294 (diff) | |
| parent | a5de4fb2a585d0d69f62abd1f1765fef430786d9 (diff) | |
| download | rust-1447f9d38ca388ca178a544534b3cff72945fa1e.tar.gz rust-1447f9d38ca388ca178a544534b3cff72945fa1e.zip | |
Auto merge of #122869 - matthiaskrgr:rollup-0navj4l, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #121619 (Experimental feature postfix match) - #122370 (Gracefully handle `AnonConst` in `diagnostic_hir_wf_check()`) - #122537 (interpret/allocation: fix aliasing issue in interpreter and refactor getters a bit) - #122542 (coverage: Clean up marker statements that aren't needed later) - #122800 (Add `NonNull::<[T]>::is_empty`.) - #122820 (Stop using `<DefId as Ord>` in various diagnostic situations) - #122847 (Suggest `RUST_MIN_STACK` workaround on overflow) - #122855 (Fix Itanium mangling usizes) - #122863 (add more ice tests ) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/ptr/non_null.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 9c0236c172a..2ac42e20d43 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -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 |
