@@ -341,7 +341,7 @@ pub struct Weak<
341341 // but it is not necessarily a valid pointer.
342342 // `Weak::new` sets this to `usize::MAX` so that it doesn’t need
343343 // 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.
345345 ptr : NonNull < ArcInner < T > > ,
346346 alloc : A ,
347347}
@@ -366,7 +366,9 @@ impl<T: ?Sized, A: Allocator> fmt::Debug for Weak<T, A> {
366366// This is repr(C) to future-proof against possible field-reordering, which
367367// would interfere with otherwise safe [into|from]_raw() of transmutable
368368// 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 ) ) ]
370372struct ArcInner < T : ?Sized > {
371373 strong : Atomic < usize > ,
372374
@@ -1622,9 +1624,9 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
16221624 pub fn as_ptr ( this : & Self ) -> * const T {
16231625 let ptr: * mut ArcInner < T > = NonNull :: as_ptr ( this. ptr ) ;
16241626
1625- // SAFETY: This cannot go through Deref::deref or RcInnerPtr ::inner because
1627+ // SAFETY: This cannot go through Deref::deref or ArcInnerPtr ::inner because
16261628 // 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`.
16281630 unsafe { & raw mut ( * ptr) . data }
16291631 }
16301632
@@ -2459,7 +2461,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
24592461 /// If any other `Arc` or [`Weak`] pointers to the same allocation exist, then
24602462 /// they must not be dereferenced or have active borrows for the duration
24612463 /// 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
24632465 /// such pointers exist, for example immediately after `Arc::new`.
24642466 ///
24652467 /// # Examples
@@ -3031,7 +3033,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
30313033 // Otherwise, we're guaranteed the pointer came from a nondangling Weak.
30323034 // SAFETY: data_offset is safe to call, as ptr references a real (potentially dropped) T.
30333035 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 .
30353037 // SAFETY: the pointer originated from a Weak, so this offset is safe.
30363038 unsafe { ptr. byte_sub ( offset) as * mut ArcInner < T > }
30373039 } ;
@@ -4024,7 +4026,7 @@ impl<T: ?Sized, A: Allocator> Unpin for Arc<T, A> {}
40244026/// valid instance of T, but the T is allowed to be dropped.
40254027unsafe fn data_offset < T : ?Sized > ( ptr : * const T ) -> usize {
40264028 // 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.
40284030 // SAFETY: since the only unsized types possible are slices, trait objects,
40294031 // and extern types, the input safety requirement is currently enough to
40304032 // satisfy the requirements of align_of_val_raw; this is an implementation
0 commit comments