@@ -341,7 +341,7 @@ pub struct Weak<
341
341
// but it is not necessarily a valid pointer.
342
342
// `Weak::new` sets this to `usize::MAX` so that it doesn’t need
343
343
// to allocate space on the heap. That's not a value a real pointer
344
- // will ever have because RcInner has alignment at least 2.
344
+ // will ever have because ArcInner has alignment at least 2.
345
345
ptr : NonNull < ArcInner < T > > ,
346
346
alloc : A ,
347
347
}
@@ -366,7 +366,9 @@ impl<T: ?Sized, A: Allocator> fmt::Debug for Weak<T, A> {
366
366
// This is repr(C) to future-proof against possible field-reordering, which
367
367
// would interfere with otherwise safe [into|from]_raw() of transmutable
368
368
// inner types.
369
- #[ repr( C ) ]
369
+ // Unlike RcInner, repr(align(2)) is not strictly required because atomic types
370
+ // have the alignment same as its size, but we use it for consistency and clarity.
371
+ #[ repr( C , align( 2 ) ) ]
370
372
struct ArcInner < T : ?Sized > {
371
373
strong : Atomic < usize > ,
372
374
@@ -1622,9 +1624,9 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
1622
1624
pub fn as_ptr ( this : & Self ) -> * const T {
1623
1625
let ptr: * mut ArcInner < T > = NonNull :: as_ptr ( this. ptr ) ;
1624
1626
1625
- // SAFETY: This cannot go through Deref::deref or RcInnerPtr ::inner because
1627
+ // SAFETY: This cannot go through Deref::deref or ArcInnerPtr ::inner because
1626
1628
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
1627
- // write through the pointer after the Rc is recovered through `from_raw`.
1629
+ // write through the pointer after the Arc is recovered through `from_raw`.
1628
1630
unsafe { & raw mut ( * ptr) . data }
1629
1631
}
1630
1632
@@ -2459,7 +2461,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
2459
2461
/// If any other `Arc` or [`Weak`] pointers to the same allocation exist, then
2460
2462
/// they must not be dereferenced or have active borrows for the duration
2461
2463
/// of the returned borrow, and their inner type must be exactly the same as the
2462
- /// inner type of this Rc (including lifetimes). This is trivially the case if no
2464
+ /// inner type of this Arc (including lifetimes). This is trivially the case if no
2463
2465
/// such pointers exist, for example immediately after `Arc::new`.
2464
2466
///
2465
2467
/// # Examples
@@ -3031,7 +3033,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
3031
3033
// Otherwise, we're guaranteed the pointer came from a nondangling Weak.
3032
3034
// SAFETY: data_offset is safe to call, as ptr references a real (potentially dropped) T.
3033
3035
let offset = unsafe { data_offset ( ptr) } ;
3034
- // Thus, we reverse the offset to get the whole RcInner .
3036
+ // Thus, we reverse the offset to get the whole ArcInner .
3035
3037
// SAFETY: the pointer originated from a Weak, so this offset is safe.
3036
3038
unsafe { ptr. byte_sub ( offset) as * mut ArcInner < T > }
3037
3039
} ;
@@ -4024,7 +4026,7 @@ impl<T: ?Sized, A: Allocator> Unpin for Arc<T, A> {}
4024
4026
/// valid instance of T, but the T is allowed to be dropped.
4025
4027
unsafe fn data_offset < T : ?Sized > ( ptr : * const T ) -> usize {
4026
4028
// Align the unsized value to the end of the ArcInner.
4027
- // Because RcInner is repr(C), it will always be the last field in memory.
4029
+ // Because ArcInner is repr(C), it will always be the last field in memory.
4028
4030
// SAFETY: since the only unsized types possible are slices, trait objects,
4029
4031
// and extern types, the input safety requirement is currently enough to
4030
4032
// satisfy the requirements of align_of_val_raw; this is an implementation
0 commit comments