@@ -1721,7 +1721,21 @@ impl<T> Weak<T> {
1721
1721
pub fn new ( ) -> Weak < T > {
1722
1722
Weak { ptr : NonNull :: new ( usize:: MAX as * mut RcBox < T > ) . expect ( "MAX is not 0" ) }
1723
1723
}
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
+ }
1724
1737
1738
+ impl < T : ?Sized > Weak < T > {
1725
1739
/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
1726
1740
///
1727
1741
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
@@ -1854,21 +1868,7 @@ impl<T> Weak<T> {
1854
1868
// SAFETY: we now have recovered the original Weak pointer, so can create the Weak.
1855
1869
Weak { ptr : unsafe { NonNull :: new_unchecked ( ptr) } }
1856
1870
}
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
- }
1870
1871
1871
- impl < T : ?Sized > Weak < T > {
1872
1872
/// Attempts to upgrade the `Weak` pointer to an [`Rc`], delaying
1873
1873
/// dropping of the inner value if successful.
1874
1874
///
0 commit comments