Rollup merge of #140685 - viliml:patch-1, r=Mark-Simulacrum

Simplify `Vec::as_non_null` implementation and make it `const`

Tracking issue: #130364.
This commit is contained in:
Matthias Krüger 2025-05-15 22:28:50 +02:00 committed by GitHub
commit 7a8fd9985d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -287,7 +287,7 @@ impl<T, A: Allocator> RawVec<T, A> {
}
#[inline]
pub(crate) fn non_null(&self) -> NonNull<T> {
pub(crate) const fn non_null(&self) -> NonNull<T> {
self.inner.non_null()
}

View file

@ -1816,10 +1816,10 @@ impl<T, A: Allocator> Vec<T, A> {
/// [`as_ptr`]: Vec::as_ptr
/// [`as_non_null`]: Vec::as_non_null
#[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
#[rustc_const_unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
#[inline]
pub fn as_non_null(&mut self) -> NonNull<T> {
// SAFETY: A `Vec` always has a non-null pointer.
unsafe { NonNull::new_unchecked(self.as_mut_ptr()) }
pub const fn as_non_null(&mut self) -> NonNull<T> {
self.buf.non_null()
}
/// Returns a reference to the underlying allocator.