@@ -1451,9 +1451,11 @@ fnptr_impls_args! { A, B, C, D, E, F, G, H, I, J, K, L }
1451
1451
/// as all other references. This macro can create a raw pointer *without* creating
1452
1452
/// a reference first.
1453
1453
///
1454
- /// Note, however, that the `expr` in `addr_of!(expr)` is still subject to all
1455
- /// the usual rules. In particular, `addr_of!(*ptr::null())` is Undefined
1456
- /// Behavior because it dereferences a null pointer.
1454
+ /// Note, however, that the `expr` in `addr_of!(expr)` is still subject to other rules:
1455
+ /// * A [dangling] pointer cannot be dereferenced. In particular, `addr_of!(*ptr::null_mut())`
1456
+ /// is undefined behavior because it dereferences a null pointer.
1457
+ /// * An [unaligned] pointer cannot be dereferenced. For example, `addr_of!((*an_unaligned_ptr).field)`
1458
+ /// is undefined behavior.
1457
1459
///
1458
1460
/// # Example
1459
1461
///
@@ -1475,6 +1477,9 @@ fnptr_impls_args! { A, B, C, D, E, F, G, H, I, J, K, L }
1475
1477
/// See [`addr_of_mut`] for how to create a pointer to unininitialized data.
1476
1478
/// Doing that with `addr_of` would not make much sense since one could only
1477
1479
/// read the data, and that would be Undefined Behavior.
1480
+ ///
1481
+ /// [dangling]: ../../reference/behavior-considered-undefined.html#dangling-pointers
1482
+ /// [unaligned]: ../../reference/type-layout.html
1478
1483
#[ stable( feature = "raw_ref_macros" , since = "1.51.0" ) ]
1479
1484
#[ rustc_macro_transparency = "semitransparent" ]
1480
1485
#[ allow_internal_unstable( raw_ref_op) ]
@@ -1491,9 +1496,11 @@ pub macro addr_of($place:expr) {
1491
1496
/// as all other references. This macro can create a raw pointer *without* creating
1492
1497
/// a reference first.
1493
1498
///
1494
- /// Note, however, that the `expr` in `addr_of_mut!(expr)` is still subject to all
1495
- /// the usual rules. In particular, `addr_of_mut!(*ptr::null_mut())` is Undefined
1496
- /// Behavior because it dereferences a null pointer.
1499
+ /// Note, however, that the `expr` in `addr_of_mut!(expr)` is still subject to other rules:
1500
+ /// * A [dangling] pointer cannot be dereferenced. In particular, `addr_of_mut!(*ptr::null_mut())`
1501
+ /// is undefined behavior because it dereferences a null pointer.
1502
+ /// * An [unaligned] pointer cannot be dereferenced. For example, `addr_of_mut!((*an_unaligned_ptr).field)`
1503
+ /// is undefined behavior.
1497
1504
///
1498
1505
/// # Examples
1499
1506
///
@@ -1531,6 +1538,9 @@ pub macro addr_of($place:expr) {
1531
1538
/// unsafe { f1_ptr.write(true); }
1532
1539
/// let init = unsafe { uninit.assume_init() };
1533
1540
/// ```
1541
+ ///
1542
+ /// [dangling]: ../../reference/behavior-considered-undefined.html#dangling-pointers
1543
+ /// [unaligned]: ../../reference/type-layout.html
1534
1544
#[ stable( feature = "raw_ref_macros" , since = "1.51.0" ) ]
1535
1545
#[ rustc_macro_transparency = "semitransparent" ]
1536
1546
#[ allow_internal_unstable( raw_ref_op) ]
0 commit comments