de-stabilize unsized raw ptr methods for Weak
This commit is contained in:
parent
257becbfe4
commit
8e0b7f988e
4 changed files with 6 additions and 50 deletions
|
@ -1749,7 +1749,7 @@ struct WeakInner<'a> {
|
||||||
strong: &'a Cell<usize>,
|
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>`.
|
/// 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,
|
/// 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.
|
// SAFETY: we now have recovered the original Weak pointer, so can create the Weak.
|
||||||
Weak { ptr: unsafe { NonNull::new_unchecked(ptr) } }
|
Weak { ptr: unsafe { NonNull::new_unchecked(ptr) } }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ?Sized> Weak<T> {
|
||||||
/// Attempts to upgrade the `Weak` pointer to an [`Rc`], delaying
|
/// Attempts to upgrade the `Weak` pointer to an [`Rc`], delaying
|
||||||
/// dropping of the inner value if successful.
|
/// dropping of the inner value if successful.
|
||||||
///
|
///
|
||||||
|
|
|
@ -208,30 +208,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]
|
#[test]
|
||||||
fn get_mut() {
|
fn get_mut() {
|
||||||
let mut x = Rc::new(3);
|
let mut x = Rc::new(3);
|
||||||
|
|
|
@ -1535,7 +1535,7 @@ struct WeakInner<'a> {
|
||||||
strong: &'a atomic::AtomicUsize,
|
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>`.
|
/// 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,
|
/// 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.
|
// SAFETY: we now have recovered the original Weak pointer, so can create the Weak.
|
||||||
unsafe { Weak { ptr: NonNull::new_unchecked(ptr) } }
|
unsafe { Weak { ptr: NonNull::new_unchecked(ptr) } }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: ?Sized> Weak<T> {
|
||||||
/// Attempts to upgrade the `Weak` pointer to an [`Arc`], delaying
|
/// Attempts to upgrade the `Weak` pointer to an [`Arc`], delaying
|
||||||
/// dropping of the inner value if successful.
|
/// dropping of the inner value if successful.
|
||||||
///
|
///
|
||||||
|
|
|
@ -158,30 +158,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]
|
#[test]
|
||||||
fn test_cowarc_clone_make_mut() {
|
fn test_cowarc_clone_make_mut() {
|
||||||
let mut cow0 = Arc::new(75);
|
let mut cow0 = Arc::new(75);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue