Skip to content

Commit

Permalink
explain that even addr_of cannot deref a NULL ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 3, 2021
1 parent a4a6bdd commit b93137a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/core/src/ptr/mod.rs
Expand Up @@ -1524,6 +1524,10 @@ fnptr_impls_args! { A, B, C, D, E, F, G, H, I, J, K, L }
/// as all other references. This macro can create a raw pointer *without* creating
/// a reference first.
///
/// Note, however, that the `expr` in `addr_of!(expr)` is still subject to all
/// the usual rules. In particular, `addr_of!(*ptr::null())` is Undefined
/// Behavior because it dereferences a NULL pointer.
///
/// # Example
///
/// ```
Expand Down Expand Up @@ -1562,6 +1566,10 @@ pub macro addr_of($place:expr) {
/// as all other references. This macro can create a raw pointer *without* creating
/// a reference first.
///
/// Note, however, that the `expr` in `addr_of_mut!(expr)` is still subject to all
/// the usual rules. In particular, `addr_of_mut!(*ptr::null_mut())` is Undefined
/// Behavior because it dereferences a NULL pointer.
///
/// # Examples
///
/// **Creating a pointer to unaligned data:**
Expand Down

0 comments on commit b93137a

Please sign in to comment.