@@ -3402,11 +3402,8 @@ macro_rules! atomic_int {
3402
3402
/// This method is mostly useful for FFI, where the function signature may use
3403
3403
#[ doc = concat!( "`*mut " , stringify!( $int_type) , "` instead of `&" , stringify!( $atomic_type) , "`." ) ]
3404
3404
///
3405
- /// Returning an `*mut` pointer from a shared reference to this atomic is safe because the
3406
- /// atomic types work with interior mutability. All modifications of an atomic change the value
3407
- /// through a shared reference, and can do so safely as long as they use atomic operations. Any
3408
- /// use of the returned raw pointer requires an `unsafe` block and still has to uphold the same
3409
- /// restriction: operations on it must not lead to data races.
3405
+ /// All modifications of an atomic change the value through a shared reference, and can do so safely
3406
+ /// as long as they use atomic operations.
3410
3407
///
3411
3408
/// # Examples
3412
3409
///
@@ -3420,12 +3417,24 @@ macro_rules! atomic_int {
3420
3417
///
3421
3418
#[ doc = concat!( "let atomic = " , stringify!( $atomic_type) , "::new(1);" ) ]
3422
3419
///
3423
- /// // SAFETY: Safe as long as `my_atomic_op` does not lead to a data race.
3420
+ /// // SAFETY: `my_atomic_op` only uses atomic operations so it will not lead to a data race.
3424
3421
/// unsafe {
3425
3422
/// my_atomic_op(atomic.as_ptr());
3426
3423
/// }
3427
3424
/// # }
3428
3425
/// ```
3426
+ ///
3427
+ /// ```
3428
+ #[ doc = concat!( $extra_feature, "use std::sync::atomic::" , stringify!( $atomic_type) , ";" ) ]
3429
+ ///
3430
+ ///
3431
+ #[ doc = concat!( "let atomic_ref_1 = " , stringify!( $atomic_type) , "::new(1);" ) ]
3432
+ #[ doc = concat!( "let atomic_ref_2 = " , stringify!( $atomic_type) , "::new(2);" ) ]
3433
+ ///
3434
+ /// // Comparison of addresses is a safe operation and does not require an `unsafe` block.
3435
+ /// let is_equal = atomic_ref_1 == atomic_ref_2;
3436
+ /// assert!(is_equal || !is_equal);
3437
+ /// ```
3429
3438
#[ inline]
3430
3439
#[ stable( feature = "atomic_as_ptr" , since = "1.70.0" ) ]
3431
3440
#[ rustc_const_stable( feature = "atomic_as_ptr" , since = "1.70.0" ) ]
0 commit comments