Skip to content

Commit e6efbb2

Browse files
committed
Document CTFE behavior of methods that call is_null
1 parent 9388917 commit e6efbb2

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

library/core/src/ptr/const_ptr.rs

+21
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ impl<T: ?Sized> *const T {
257257
/// When calling this method, you have to ensure that *either* the pointer is null *or*
258258
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
259259
///
260+
/// # Panics during const evaluation
261+
///
262+
/// This method will panic during const evaluation if the pointer cannot be
263+
/// determined to be null or not. See [`is_null`] for more information.
264+
///
265+
/// [`is_null`]: #method.is_null
266+
///
260267
/// # Examples
261268
///
262269
/// ```
@@ -334,6 +341,13 @@ impl<T: ?Sized> *const T {
334341
/// When calling this method, you have to ensure that *either* the pointer is null *or*
335342
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
336343
///
344+
/// # Panics during const evaluation
345+
///
346+
/// This method will panic during const evaluation if the pointer cannot be
347+
/// determined to be null or not. See [`is_null`] for more information.
348+
///
349+
/// [`is_null`]: #method.is_null
350+
///
337351
/// # Examples
338352
///
339353
/// ```
@@ -1607,6 +1621,13 @@ impl<T> *const [T] {
16071621
///
16081622
/// [valid]: crate::ptr#safety
16091623
/// [allocated object]: crate::ptr#allocated-object
1624+
///
1625+
/// # Panics during const evaluation
1626+
///
1627+
/// This method will panic during const evaluation if the pointer cannot be
1628+
/// determined to be null or not. See [`is_null`] for more information.
1629+
///
1630+
/// [`is_null`]: #method.is_null
16101631
#[inline]
16111632
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
16121633
pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]> {

library/core/src/ptr/mut_ptr.rs

+41
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ impl<T: ?Sized> *mut T {
246246
/// When calling this method, you have to ensure that *either* the pointer is null *or*
247247
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
248248
///
249+
/// # Panics during const evaluation
250+
///
251+
/// This method will panic during const evaluation if the pointer cannot be
252+
/// determined to be null or not. See [`is_null`] for more information.
253+
///
254+
/// [`is_null`]: #method.is_null-1
255+
///
249256
/// # Examples
250257
///
251258
/// ```
@@ -330,6 +337,13 @@ impl<T: ?Sized> *mut T {
330337
/// Note that because the created reference is to `MaybeUninit<T>`, the
331338
/// source pointer can point to uninitialized memory.
332339
///
340+
/// # Panics during const evaluation
341+
///
342+
/// This method will panic during const evaluation if the pointer cannot be
343+
/// determined to be null or not. See [`is_null`] for more information.
344+
///
345+
/// [`is_null`]: #method.is_null-1
346+
///
333347
/// # Examples
334348
///
335349
/// ```
@@ -593,6 +607,12 @@ impl<T: ?Sized> *mut T {
593607
/// the pointer is null *or*
594608
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
595609
///
610+
/// # Panics during const evaluation
611+
///
612+
/// This method will panic during const evaluation if the pointer cannot be
613+
/// determined to be null or not. See [`is_null`] for more information.
614+
///
615+
/// [`is_null`]: #method.is_null-1
596616
///
597617
/// # Examples
598618
///
@@ -676,6 +696,13 @@ impl<T: ?Sized> *mut T {
676696
///
677697
/// When calling this method, you have to ensure that *either* the pointer is null *or*
678698
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
699+
///
700+
/// # Panics during const evaluation
701+
///
702+
/// This method will panic during const evaluation if the pointer cannot be
703+
/// determined to be null or not. See [`is_null`] for more information.
704+
///
705+
/// [`is_null`]: #method.is_null-1
679706
#[inline]
680707
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
681708
pub const unsafe fn as_uninit_mut<'a>(self) -> Option<&'a mut MaybeUninit<T>>
@@ -1952,6 +1979,13 @@ impl<T> *mut [T] {
19521979
///
19531980
/// [valid]: crate::ptr#safety
19541981
/// [allocated object]: crate::ptr#allocated-object
1982+
///
1983+
/// # Panics during const evaluation
1984+
///
1985+
/// This method will panic during const evaluation if the pointer cannot be
1986+
/// determined to be null or not. See [`is_null`] for more information.
1987+
///
1988+
/// [`is_null`]: #method.is_null-1
19551989
#[inline]
19561990
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
19571991
pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]> {
@@ -2003,6 +2037,13 @@ impl<T> *mut [T] {
20032037
///
20042038
/// [valid]: crate::ptr#safety
20052039
/// [allocated object]: crate::ptr#allocated-object
2040+
///
2041+
/// # Panics during const evaluation
2042+
///
2043+
/// This method will panic during const evaluation if the pointer cannot be
2044+
/// determined to be null or not. See [`is_null`] for more information.
2045+
///
2046+
/// [`is_null`]: #method.is_null-1
20062047
#[inline]
20072048
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
20082049
pub const unsafe fn as_uninit_slice_mut<'a>(self) -> Option<&'a mut [MaybeUninit<T>]> {

library/core/src/ptr/non_null.rs

+7
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ impl<T: ?Sized> NonNull<T> {
204204

205205
/// Creates a new `NonNull` if `ptr` is non-null.
206206
///
207+
/// # Panics during const evaluation
208+
///
209+
/// This method will panic during const evaluation if the pointer cannot be
210+
/// determined to be null or not. See [`is_null`] for more information.
211+
///
212+
/// [`is_null`]: ../primitive.pointer.html#method.is_null-1
213+
///
207214
/// # Examples
208215
///
209216
/// ```

0 commit comments

Comments
 (0)