diff options
| author | Ralf Jung <post@ralfj.de> | 2020-12-28 00:39:09 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-12-28 00:39:09 +0100 |
| commit | 8e0b7f988ee4e12d79c03ed53b3b59fee534330e (patch) | |
| tree | 95a69333090d402f2544306364e7bea07cd15a04 | |
| parent | 257becbfe4987d1f7b12af5a8dd5ed96697cd2e8 (diff) | |
| download | rust-8e0b7f988ee4e12d79c03ed53b3b59fee534330e.tar.gz rust-8e0b7f988ee4e12d79c03ed53b3b59fee534330e.zip | |
de-stabilize unsized raw ptr methods for Weak
| -rw-r--r-- | library/alloc/src/rc.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/rc/tests.rs | 24 | ||||
| -rw-r--r-- | library/alloc/src/sync.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/sync/tests.rs | 24 |
4 files changed, 6 insertions, 50 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index a96be57143d..73d12f0a5f4 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1749,7 +1749,7 @@ struct WeakInner<'a> { strong: &'a Cell<usize>, } -impl<T: ?Sized> Weak<T> { +impl<T> Weak<T> { /// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`. /// /// The pointer is valid only if there are some strong references. The pointer may be dangling, @@ -1882,7 +1882,9 @@ impl<T: ?Sized> Weak<T> { // SAFETY: we now have recovered the original Weak pointer, so can create the Weak. Weak { ptr: unsafe { NonNull::new_unchecked(ptr) } } } +} +impl<T: ?Sized> Weak<T> { /// Attempts to upgrade the `Weak` pointer to an [`Rc`], delaying /// dropping of the inner value if successful. /// diff --git a/library/alloc/src/rc/tests.rs b/library/alloc/src/rc/tests.rs index bb5c3f4f904..2d183a8c88c 100644 --- a/library/alloc/src/rc/tests.rs +++ b/library/alloc/src/rc/tests.rs @@ -209,30 +209,6 @@ fn into_from_weak_raw() { } #[test] -fn test_into_from_weak_raw_unsized() { - use std::fmt::Display; - use std::string::ToString; - - let arc: Rc<str> = Rc::from("foo"); - let weak: Weak<str> = Rc::downgrade(&arc); - - let ptr = Weak::into_raw(weak.clone()); - let weak2 = unsafe { Weak::from_raw(ptr) }; - - assert_eq!(unsafe { &*ptr }, "foo"); - assert!(weak.ptr_eq(&weak2)); - - let arc: Rc<dyn Display> = Rc::new(123); - let weak: Weak<dyn Display> = Rc::downgrade(&arc); - - let ptr = Weak::into_raw(weak.clone()); - let weak2 = unsafe { Weak::from_raw(ptr) }; - - assert_eq!(unsafe { &*ptr }.to_string(), "123"); - assert!(weak.ptr_eq(&weak2)); -} - -#[test] fn get_mut() { let mut x = Rc::new(3); *Rc::get_mut(&mut x).unwrap() = 4; diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 9d478a302e9..53ba9c283ae 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1535,7 +1535,7 @@ struct WeakInner<'a> { strong: &'a atomic::AtomicUsize, } -impl<T: ?Sized> Weak<T> { +impl<T> Weak<T> { /// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`. /// /// The pointer is valid only if there are some strong references. The pointer may be dangling, @@ -1668,7 +1668,9 @@ impl<T: ?Sized> Weak<T> { // SAFETY: we now have recovered the original Weak pointer, so can create the Weak. unsafe { Weak { ptr: NonNull::new_unchecked(ptr) } } } +} +impl<T: ?Sized> Weak<T> { /// Attempts to upgrade the `Weak` pointer to an [`Arc`], delaying /// dropping of the inner value if successful. /// diff --git a/library/alloc/src/sync/tests.rs b/library/alloc/src/sync/tests.rs index 77f328d48f9..e8e1e66da5e 100644 --- a/library/alloc/src/sync/tests.rs +++ b/library/alloc/src/sync/tests.rs @@ -159,30 +159,6 @@ fn into_from_weak_raw() { } #[test] -fn test_into_from_weak_raw_unsized() { - use std::fmt::Display; - use std::string::ToString; - - let arc: Arc<str> = Arc::from("foo"); - let weak: Weak<str> = Arc::downgrade(&arc); - - let ptr = Weak::into_raw(weak.clone()); - let weak2 = unsafe { Weak::from_raw(ptr) }; - - assert_eq!(unsafe { &*ptr }, "foo"); - assert!(weak.ptr_eq(&weak2)); - - let arc: Arc<dyn Display> = Arc::new(123); - let weak: Weak<dyn Display> = Arc::downgrade(&arc); - - let ptr = Weak::into_raw(weak.clone()); - let weak2 = unsafe { Weak::from_raw(ptr) }; - - assert_eq!(unsafe { &*ptr }.to_string(), "123"); - assert!(weak.ptr_eq(&weak2)); -} - -#[test] fn test_cowarc_clone_make_mut() { let mut cow0 = Arc::new(75); let mut cow1 = cow0.clone(); |
