Skip to content

Commit 207c52d

Browse files
committed
Relax bounds of rc::Weak::as_ptr and friends
....to allow use with unsized T. This is a follow-up to rust-lang#73845, which did the impl work required to be able to relax these bounds.
1 parent dbf3ae7 commit 207c52d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/liballoc/rc.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,14 @@ impl<T> Weak<T> {
16751675
pub fn new() -> Weak<T> {
16761676
Weak { ptr: NonNull::new(usize::MAX as *mut RcBox<T>).expect("MAX is not 0") }
16771677
}
1678+
}
16781679

1680+
pub(crate) fn is_dangling<T: ?Sized>(ptr: NonNull<T>) -> bool {
1681+
let address = ptr.as_ptr() as *mut () as usize;
1682+
address == usize::MAX
1683+
}
1684+
1685+
impl<T: ?Sized> Weak<T> {
16791686
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
16801687
///
16811688
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
@@ -1808,14 +1815,7 @@ impl<T> Weak<T> {
18081815
}
18091816
}
18101817
}
1811-
}
18121818

1813-
pub(crate) fn is_dangling<T: ?Sized>(ptr: NonNull<T>) -> bool {
1814-
let address = ptr.as_ptr() as *mut () as usize;
1815-
address == usize::MAX
1816-
}
1817-
1818-
impl<T: ?Sized> Weak<T> {
18191819
/// Attempts to upgrade the `Weak` pointer to an [`Rc`], delaying
18201820
/// dropping of the inner value if successful.
18211821
///

0 commit comments

Comments
 (0)