Auto merge of #117572 - RalfJung:addr_of, r=cuviper · rust-lang/rust@17d0a45 (original) (raw)
`@@ -1999,9 +1999,18 @@ impl<F: FnPtr> fmt::Debug for F {
`
1999
1999
`/// as all other references. This macro can create a raw pointer without creating
`
2000
2000
`/// a reference first.
`
2001
2001
`///
`
2002
``
`` -
/// Note, however, that the expr in addr_of!(expr) is still subject to all
``
2003
``
`` -
/// the usual rules. In particular, addr_of!(*ptr::null()) is Undefined
``
2004
``
`-
/// Behavior because it dereferences a null pointer.
`
``
2002
`` +
/// The expr in addr_of!(expr) is evaluated as a place expression, but never loads
``
``
2003
`+
/// from the place or requires the place to be dereferenceable. This means that
`
``
2004
`` +
/// addr_of!(*ptr) is defined behavior even if ptr is null, dangling, or misaligned.
``
``
2005
`` +
/// Note however that addr_of!((*ptr).field) still requires the projection to
``
``
2006
`` +
/// field to be in-bounds, using the same rules as [offset].
``
``
2007
`+
///
`
``
2008
`` +
/// Note that Deref/Index coercions (and their mutable counterparts) are applied inside
``
``
2009
`` +
/// addr_of! like everywhere else, in which case a reference is created to call Deref::deref or
``
``
2010
`` +
/// Index::index, respectively. The statements above only apply when no such coercions are
``
``
2011
`+
/// applied.
`
``
2012
`+
///
`
``
2013
`` +
/// [offset]: pointer::offset
``
2005
2014
`///
`
2006
2015
`/// # Example
`
2007
2016
`///
`
`@@ -2039,9 +2048,18 @@ pub macro addr_of($place:expr) {
`
2039
2048
`/// as all other references. This macro can create a raw pointer without creating
`
2040
2049
`/// a reference first.
`
2041
2050
`///
`
2042
``
`` -
/// Note, however, that the expr in addr_of_mut!(expr) is still subject to all
``
2043
``
`` -
/// the usual rules. In particular, addr_of_mut!(*ptr::null_mut()) is Undefined
``
2044
``
`-
/// Behavior because it dereferences a null pointer.
`
``
2051
`` +
/// The expr in addr_of_mut!(expr) is evaluated as a place expression, but never loads
``
``
2052
`+
/// from the place or requires the place to be dereferenceable. This means that
`
``
2053
`` +
/// addr_of_mut!(*ptr) is defined behavior even if ptr is null, dangling, or misaligned.
``
``
2054
`` +
/// Note however that addr_of_mut!((*ptr).field) still requires the projection to
``
``
2055
`` +
/// field to be in-bounds, using the same rules as [offset].
``
``
2056
`+
///
`
``
2057
`` +
/// Note that Deref/Index coercions (and their mutable counterparts) are applied inside
``
``
2058
`` +
/// addr_of_mut! like everywhere else, in which case a reference is created to call Deref::deref
``
``
2059
`` +
/// or Index::index, respectively. The statements above only apply when no such coercions are
``
``
2060
`+
/// applied.
`
``
2061
`+
///
`
``
2062
`` +
/// [offset]: pointer::offset
``
2045
2063
`///
`
2046
2064
`/// # Examples
`
2047
2065
`///
`