diff options
| author | Zachary S <zasample18+github@gmail.com> | 2024-05-19 11:42:35 -0500 |
|---|---|---|
| committer | Zachary S <zasample18+github@gmail.com> | 2024-05-19 11:42:35 -0500 |
| commit | 2dacd70e1e65cb078e7459295f99c457dc836bac (patch) | |
| tree | f99a7f66a571c1c4cbce76c4efd75f476bcc80f3 | |
| parent | e6396bca013b1b4cc1a177ef11e8fd5c270a4ea5 (diff) | |
| download | rust-2dacd70e1e65cb078e7459295f99c457dc836bac.tar.gz rust-2dacd70e1e65cb078e7459295f99c457dc836bac.zip | |
Fix stacked borrows violation
| -rw-r--r-- | library/alloc/src/sync.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 9081ea5c679..89dbf9f5cdd 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -3381,7 +3381,11 @@ impl<T> Default for Arc<[T]> { #[inline] fn default() -> Self { if mem::align_of::<T>() <= MAX_STATIC_INNER_SLICE_ALIGNMENT { - let inner: NonNull<ArcInner<[u8; 1]>> = NonNull::from(&STATIC_INNER_SLICE.inner); + // We take a reference to the whole struct instead of the ArcInner<[u8; 1]> inside it so + // we don't shrink the range of bytes the ptr is allowed to access under Stacked Borrows. + // (Miri complains on 32-bit targets with Arc<[Align16]> otherwise.) + // (Note that NonNull::from(&STATIC_INNER_SLICE.inner) is fine under Tree Borrows.) + let inner: NonNull<SliceArcInnerForStatic> = NonNull::from(&STATIC_INNER_SLICE); let inner: NonNull<ArcInner<[T; 0]>> = inner.cast(); // `this` semantically is the Arc "owned" by the static, so make sure not to drop it. let this: mem::ManuallyDrop<Arc<[T; 0]>> = unsafe { mem::ManuallyDrop::new(Arc::from_inner(inner)) }; |
