Skip to content

Commit 9d04715

Browse files
theemathascuviper
authored andcommitted
Document CTFE behavior of methods that call is_null
(cherry picked from commit e6efbb2)
1 parent 4171701 commit 9d04715

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
@@ -258,6 +258,13 @@ impl<T: ?Sized> *const T {
258258
/// When calling this method, you have to ensure that *either* the pointer is null *or*
259259
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
260260
///
261+
/// # Panics during const evaluation
262+
///
263+
/// This method will panic during const evaluation if the pointer cannot be
264+
/// determined to be null or not. See [`is_null`] for more information.
265+
///
266+
/// [`is_null`]: #method.is_null
267+
///
261268
/// # Examples
262269
///
263270
/// ```
@@ -335,6 +342,13 @@ impl<T: ?Sized> *const T {
335342
/// When calling this method, you have to ensure that *either* the pointer is null *or*
336343
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
337344
///
345+
/// # Panics during const evaluation
346+
///
347+
/// This method will panic during const evaluation if the pointer cannot be
348+
/// determined to be null or not. See [`is_null`] for more information.
349+
///
350+
/// [`is_null`]: #method.is_null
351+
///
338352
/// # Examples
339353
///
340354
/// ```
@@ -1595,6 +1609,13 @@ impl<T> *const [T] {
15951609
///
15961610
/// [valid]: crate::ptr#safety
15971611
/// [allocated object]: crate::ptr#allocated-object
1612+
///
1613+
/// # Panics during const evaluation
1614+
///
1615+
/// This method will panic during const evaluation if the pointer cannot be
1616+
/// determined to be null or not. See [`is_null`] for more information.
1617+
///
1618+
/// [`is_null`]: #method.is_null
15981619
#[inline]
15991620
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
16001621
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]

library/core/src/ptr/mut_ptr.rs

+41
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ impl<T: ?Sized> *mut T {
247247
/// When calling this method, you have to ensure that *either* the pointer is null *or*
248248
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
249249
///
250+
/// # Panics during const evaluation
251+
///
252+
/// This method will panic during const evaluation if the pointer cannot be
253+
/// determined to be null or not. See [`is_null`] for more information.
254+
///
255+
/// [`is_null`]: #method.is_null-1
256+
///
250257
/// # Examples
251258
///
252259
/// ```
@@ -331,6 +338,13 @@ impl<T: ?Sized> *mut T {
331338
/// Note that because the created reference is to `MaybeUninit<T>`, the
332339
/// source pointer can point to uninitialized memory.
333340
///
341+
/// # Panics during const evaluation
342+
///
343+
/// This method will panic during const evaluation if the pointer cannot be
344+
/// determined to be null or not. See [`is_null`] for more information.
345+
///
346+
/// [`is_null`]: #method.is_null-1
347+
///
334348
/// # Examples
335349
///
336350
/// ```
@@ -595,6 +609,12 @@ impl<T: ?Sized> *mut T {
595609
/// the pointer is null *or*
596610
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
597611
///
612+
/// # Panics during const evaluation
613+
///
614+
/// This method will panic during const evaluation if the pointer cannot be
615+
/// determined to be null or not. See [`is_null`] for more information.
616+
///
617+
/// [`is_null`]: #method.is_null-1
598618
///
599619
/// # Examples
600620
///
@@ -678,6 +698,13 @@ impl<T: ?Sized> *mut T {
678698
///
679699
/// When calling this method, you have to ensure that *either* the pointer is null *or*
680700
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
701+
///
702+
/// # Panics during const evaluation
703+
///
704+
/// This method will panic during const evaluation if the pointer cannot be
705+
/// determined to be null or not. See [`is_null`] for more information.
706+
///
707+
/// [`is_null`]: #method.is_null-1
681708
#[inline]
682709
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
683710
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
@@ -1950,6 +1977,13 @@ impl<T> *mut [T] {
19501977
///
19511978
/// [valid]: crate::ptr#safety
19521979
/// [allocated object]: crate::ptr#allocated-object
1980+
///
1981+
/// # Panics during const evaluation
1982+
///
1983+
/// This method will panic during const evaluation if the pointer cannot be
1984+
/// determined to be null or not. See [`is_null`] for more information.
1985+
///
1986+
/// [`is_null`]: #method.is_null-1
19531987
#[inline]
19541988
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
19551989
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]
@@ -2002,6 +2036,13 @@ impl<T> *mut [T] {
20022036
///
20032037
/// [valid]: crate::ptr#safety
20042038
/// [allocated object]: crate::ptr#allocated-object
2039+
///
2040+
/// # Panics during const evaluation
2041+
///
2042+
/// This method will panic during const evaluation if the pointer cannot be
2043+
/// determined to be null or not. See [`is_null`] for more information.
2044+
///
2045+
/// [`is_null`]: #method.is_null-1
20052046
#[inline]
20062047
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
20072048
#[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")]

library/core/src/ptr/non_null.rs

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

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

0 commit comments

Comments
 (0)