Skip to content

Commit 44037db

Browse files
committed
Fix stacked borrows violation
1 parent 1920ed9 commit 44037db

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

alloc/src/sync.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -3381,7 +3381,11 @@ impl<T> Default for Arc<[T]> {
33813381
#[inline]
33823382
fn default() -> Self {
33833383
if mem::align_of::<T>() <= MAX_STATIC_INNER_SLICE_ALIGNMENT {
3384-
let inner: NonNull<ArcInner<[u8; 1]>> = NonNull::from(&STATIC_INNER_SLICE.inner);
3384+
// We take a reference to the whole struct instead of the ArcInner<[u8; 1]> inside it so
3385+
// we don't shrink the range of bytes the ptr is allowed to access under Stacked Borrows.
3386+
// (Miri complains on 32-bit targets with Arc<[Align16]> otherwise.)
3387+
// (Note that NonNull::from(&STATIC_INNER_SLICE.inner) is fine under Tree Borrows.)
3388+
let inner: NonNull<SliceArcInnerForStatic> = NonNull::from(&STATIC_INNER_SLICE);
33853389
let inner: NonNull<ArcInner<[T; 0]>> = inner.cast();
33863390
// `this` semantically is the Arc "owned" by the static, so make sure not to drop it.
33873391
let this: mem::ManuallyDrop<Arc<[T; 0]>> = unsafe { mem::ManuallyDrop::new(Arc::from_inner(inner)) };

0 commit comments

Comments
 (0)