@@ -1989,9 +1989,13 @@ impl<F: FnPtr> fmt::Debug for F {
1989
1989
/// as all other references. This macro can create a raw pointer *without* creating
1990
1990
/// a reference first.
1991
1991
///
1992
- /// Note, however, that the `expr` in `addr_of!(expr)` is still subject to all
1993
- /// the usual rules. In particular, `addr_of!(*ptr::null())` is Undefined
1994
- /// Behavior because it dereferences a null pointer.
1992
+ /// The `expr` in `addr_of!(expr)` is evaluated as a place expression, but never loads
1993
+ /// from the place or requires the place to be dereferenceable. This means that
1994
+ /// `addr_of!(*ptr)` is defined behavior even if `ptr` is dangling or misaligned.
1995
+ /// Note however that `addr_of!((*ptr).field)` still requires the projection to
1996
+ /// `field` to be in-bounds, using the same rules as [`offset`].
1997
+ ///
1998
+ /// [`offset`]: pointer::offset
1995
1999
///
1996
2000
/// # Example
1997
2001
///
@@ -2029,9 +2033,13 @@ pub macro addr_of($place:expr) {
2029
2033
/// as all other references. This macro can create a raw pointer *without* creating
2030
2034
/// a reference first.
2031
2035
///
2032
- /// Note, however, that the `expr` in `addr_of_mut!(expr)` is still subject to all
2033
- /// the usual rules. In particular, `addr_of_mut!(*ptr::null_mut())` is Undefined
2034
- /// Behavior because it dereferences a null pointer.
2036
+ /// The `expr` in `addr_of_mut!(expr)` is evaluated as a place expression, but never loads
2037
+ /// from the place or requires the place to be dereferenceable. This means that
2038
+ /// `addr_of_mut!(*ptr)` is defined behavior even if `ptr` is dangling or misaligned.
2039
+ /// Note however that `addr_of_mut!((*ptr).field)` still requires the projection to
2040
+ /// `field` to be in-bounds, using the same rules as [`offset`].
2041
+ ///
2042
+ /// [`offset`]: pointer::offset
2035
2043
///
2036
2044
/// # Examples
2037
2045
///
0 commit comments