Skip to content

Commit b93137a

Browse files
committed
explain that even addr_of cannot deref a NULL ptr
1 parent a4a6bdd commit b93137a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/core/src/ptr/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,10 @@ fnptr_impls_args! { A, B, C, D, E, F, G, H, I, J, K, L }
15241524
/// as all other references. This macro can create a raw pointer *without* creating
15251525
/// a reference first.
15261526
///
1527+
/// Note, however, that the `expr` in `addr_of!(expr)` is still subject to all
1528+
/// the usual rules. In particular, `addr_of!(*ptr::null())` is Undefined
1529+
/// Behavior because it dereferences a NULL pointer.
1530+
///
15271531
/// # Example
15281532
///
15291533
/// ```
@@ -1562,6 +1566,10 @@ pub macro addr_of($place:expr) {
15621566
/// as all other references. This macro can create a raw pointer *without* creating
15631567
/// a reference first.
15641568
///
1569+
/// Note, however, that the `expr` in `addr_of_mut!(expr)` is still subject to all
1570+
/// the usual rules. In particular, `addr_of_mut!(*ptr::null_mut())` is Undefined
1571+
/// Behavior because it dereferences a NULL pointer.
1572+
///
15651573
/// # Examples
15661574
///
15671575
/// **Creating a pointer to unaligned data:**

0 commit comments

Comments
 (0)