Skip to content

Commit fc11361

Browse files
Rollup merge of rust-lang#140685 - viliml:patch-1, r=Mark-Simulacrum
Simplify `Vec::as_non_null` implementation and make it `const` Tracking issue: rust-lang#130364.
2 parents 56df335 + 53459ff commit fc11361

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

library/alloc/src/raw_vec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<T, A: Allocator> RawVec<T, A> {
287287
}
288288

289289
#[inline]
290-
pub(crate) fn non_null(&self) -> NonNull<T> {
290+
pub(crate) const fn non_null(&self) -> NonNull<T> {
291291
self.inner.non_null()
292292
}
293293

library/alloc/src/vec/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1816,10 +1816,10 @@ impl<T, A: Allocator> Vec<T, A> {
18161816
/// [`as_ptr`]: Vec::as_ptr
18171817
/// [`as_non_null`]: Vec::as_non_null
18181818
#[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
1819+
#[rustc_const_unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
18191820
#[inline]
1820-
pub fn as_non_null(&mut self) -> NonNull<T> {
1821-
// SAFETY: A `Vec` always has a non-null pointer.
1822-
unsafe { NonNull::new_unchecked(self.as_mut_ptr()) }
1821+
pub const fn as_non_null(&mut self) -> NonNull<T> {
1822+
self.buf.non_null()
18231823
}
18241824

18251825
/// Returns a reference to the underlying allocator.

0 commit comments

Comments
 (0)