@@ -1721,7 +1721,21 @@ impl<T> Weak<T> {
17211721 pub fn new ( ) -> Weak < T > {
17221722 Weak { ptr : NonNull :: new ( usize:: MAX as * mut RcBox < T > ) . expect ( "MAX is not 0" ) }
17231723 }
1724+ }
1725+
1726+ pub ( crate ) fn is_dangling < T : ?Sized > ( ptr : NonNull < T > ) -> bool {
1727+ let address = ptr. as_ptr ( ) as * mut ( ) as usize ;
1728+ address == usize:: MAX
1729+ }
1730+
1731+ /// Helper type to allow accessing the reference counts without
1732+ /// making any assertions about the data field.
1733+ struct WeakInner < ' a > {
1734+ weak : & ' a Cell < usize > ,
1735+ strong : & ' a Cell < usize > ,
1736+ }
17241737
1738+ impl < T : ?Sized > Weak < T > {
17251739 /// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
17261740 ///
17271741 /// The pointer is valid only if there are some strong references. The pointer may be dangling,
@@ -1854,21 +1868,7 @@ impl<T> Weak<T> {
18541868 // SAFETY: we now have recovered the original Weak pointer, so can create the Weak.
18551869 Weak { ptr : unsafe { NonNull :: new_unchecked ( ptr) } }
18561870 }
1857- }
1858-
1859- pub ( crate ) fn is_dangling < T : ?Sized > ( ptr : NonNull < T > ) -> bool {
1860- let address = ptr. as_ptr ( ) as * mut ( ) as usize ;
1861- address == usize:: MAX
1862- }
1863-
1864- /// Helper type to allow accessing the reference counts without
1865- /// making any assertions about the data field.
1866- struct WeakInner < ' a > {
1867- weak : & ' a Cell < usize > ,
1868- strong : & ' a Cell < usize > ,
1869- }
18701871
1871- impl < T : ?Sized > Weak < T > {
18721872 /// Attempts to upgrade the `Weak` pointer to an [`Rc`], delaying
18731873 /// dropping of the inner value if successful.
18741874 ///
0 commit comments