diff options
| author | est31 <MTest31@outlook.com> | 2023-08-05 14:01:56 +0200 |
|---|---|---|
| committer | est31 <MTest31@outlook.com> | 2023-08-06 00:20:28 +0200 |
| commit | 33970db8c6a50a4a8c0fbb3d7d94893de24b98b5 (patch) | |
| tree | 117c8f07e3e770f75ae80c4bab5a4bd64ca51309 /library/core/src/ptr | |
| parent | 8cfa4fe6b2268385480dc4a88ce3e6fdb06a3596 (diff) | |
| download | rust-33970db8c6a50a4a8c0fbb3d7d94893de24b98b5.tar.gz rust-33970db8c6a50a4a8c0fbb3d7d94893de24b98b5.zip | |
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.
Diffstat (limited to 'library/core/src/ptr')
| -rw-r--r-- | library/core/src/ptr/mod.rs | 2 | ||||
| -rw-r--r-- | library/core/src/ptr/non_null.rs | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 5f094ac4e7e..84cc2e474a1 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -698,6 +698,7 @@ where #[inline(always)] #[must_use] #[unstable(feature = "ptr_from_ref", issue = "106116")] +#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)] #[rustc_diagnostic_item = "ptr_from_ref"] pub const fn from_ref<T: ?Sized>(r: &T) -> *const T { r @@ -710,6 +711,7 @@ pub const fn from_ref<T: ?Sized>(r: &T) -> *const T { #[inline(always)] #[must_use] #[unstable(feature = "ptr_from_ref", issue = "106116")] +#[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)] #[rustc_diagnostic_item = "ptr_from_mut"] pub const fn from_mut<T: ?Sized>(r: &mut T) -> *mut T { r diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 9582ca9e0be..77a2e0775a3 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -320,6 +320,7 @@ impl<T: ?Sized> NonNull<T> { /// ``` #[stable(feature = "nonnull", since = "1.25.0")] #[rustc_const_stable(feature = "const_nonnull_as_ptr", since = "1.32.0")] + #[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)] #[must_use] #[inline(always)] pub const fn as_ptr(self) -> *mut T { @@ -579,6 +580,7 @@ impl<T> NonNull<[T]> { #[must_use] #[unstable(feature = "slice_ptr_get", issue = "74265")] #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] + #[cfg_attr(not(bootstrap), rustc_never_returns_null_ptr)] pub const fn as_mut_ptr(self) -> *mut T { self.as_non_null_ptr().as_ptr() } |
