diff options
| author | Andrew Paseltiner <apaseltiner@gmail.com> | 2015-10-16 11:54:05 -0400 |
|---|---|---|
| committer | Andrew Paseltiner <apaseltiner@gmail.com> | 2015-10-16 18:35:31 -0400 |
| commit | d6bd8d8491e89277edbfc9a4e0f8953847abbdd6 (patch) | |
| tree | 41bc1358ed0b4712768d308ea3e0df04e25eddf5 /src/liballoc/rc.rs | |
| parent | 05cfd72ed1934c92af08dbcb66fd1af6b1298721 (diff) | |
| download | rust-d6bd8d8491e89277edbfc9a4e0f8953847abbdd6.tar.gz rust-d6bd8d8491e89277edbfc9a4e0f8953847abbdd6.zip | |
Add `Shared` pointer and have `{Arc, Rc}` use it
This change has two consequences: 1. It makes `Arc<T>` and `Rc<T>` covariant in `T`. 2. It causes the compiler to reject code that was unsound with respect to dropck. See compile-fail/issue-29106.rs for an example of code that no longer compiles. Because of this, this is a [breaking-change]. Fixes #29037. Fixes #29106.
Diffstat (limited to 'src/liballoc/rc.rs')
| -rw-r--r-- | src/liballoc/rc.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 4753bb2379a..d695c0edd1d 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -163,9 +163,8 @@ use core::hash::{Hasher, Hash}; use core::intrinsics::{assume, drop_in_place, abort}; use core::marker::{self, Unsize}; use core::mem::{self, align_of_val, size_of_val, forget}; -use core::nonzero::NonZero; use core::ops::{CoerceUnsized, Deref}; -use core::ptr; +use core::ptr::{self, Shared}; use heap::deallocate; @@ -184,12 +183,13 @@ struct RcBox<T: ?Sized> { pub struct Rc<T: ?Sized> { // FIXME #12808: strange names to try to avoid interfering with field // accesses of the contained type via Deref - _ptr: NonZero<*mut RcBox<T>>, + _ptr: Shared<RcBox<T>>, } impl<T: ?Sized> !marker::Send for Rc<T> {} impl<T: ?Sized> !marker::Sync for Rc<T> {} +#[cfg(not(stage0))] // remove cfg after new snapshot impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Rc<U>> for Rc<T> {} impl<T> Rc<T> { @@ -210,7 +210,7 @@ impl<T> Rc<T> { // pointers, which ensures that the weak destructor never frees // the allocation while the strong destructor is running, even // if the weak pointer is stored inside the strong one. - _ptr: NonZero::new(Box::into_raw(box RcBox { + _ptr: Shared::new(Box::into_raw(box RcBox { strong: Cell::new(1), weak: Cell::new(1), value: value, @@ -712,12 +712,13 @@ impl<T> fmt::Pointer for Rc<T> { pub struct Weak<T: ?Sized> { // FIXME #12808: strange names to try to avoid interfering with // field accesses of the contained type via Deref - _ptr: NonZero<*mut RcBox<T>>, + _ptr: Shared<RcBox<T>>, } impl<T: ?Sized> !marker::Send for Weak<T> {} impl<T: ?Sized> !marker::Sync for Weak<T> {} +#[cfg(not(stage0))] // remove cfg after new snapshot impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {} impl<T: ?Sized> Weak<T> { |
