1
Fork 0

Add #[rustc_never_returns_null_ptr] to std functions

Add the attribute to standard library functions that
are guaranteed to never return null pointers, as their
originating data wouldn't allow it.
This commit is contained in:
est31 2023-08-05 14:01:56 +02:00
parent 8cfa4fe6b2
commit 33970db8c6
10 changed files with 22 additions and 0 deletions

View file

@ -1233,6 +1233,7 @@ impl<T, A: Allocator> Vec<T, A> {
///
/// [`as_mut_ptr`]: Vec::as_mut_ptr
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)]
#[inline]
pub fn as_ptr(&self) -> *const T {
// We shadow the slice method of the same name to avoid going through
@ -1266,6 +1267,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// assert_eq!(&*x, &[0, 1, 2, 3]);
/// ```
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)]
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut T {
// We shadow the slice method of the same name to avoid going through