about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorCAD97 <cad97@cad97.com>2020-07-08 16:24:56 -0400
committerCAD97 <cad97@cad97.com>2020-09-12 10:38:22 -0500
commit0c61ce2cf0560577923abafab2e5bfce14516525 (patch)
treeb416f9ae80be235d6abda2023dbdc7c8573c98db /library/alloc/src
parent728938346b02a9688c44253c19b15baa7551fd80 (diff)
?Sized bounds for rc::Weak::as_ptr and friends
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/rc.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs
index 27e6e110903..1d4ce8e2682 100644
--- a/library/alloc/src/rc.rs
+++ b/library/alloc/src/rc.rs
@@ -1721,7 +1721,21 @@ impl<T> Weak<T> {
     pub fn new() -> Weak<T> {
         Weak { ptr: NonNull::new(usize::MAX as *mut RcBox<T>).expect("MAX is not 0") }
     }
+}
+
+pub(crate) fn is_dangling<T: ?Sized>(ptr: NonNull<T>) -> bool {
+    let address = ptr.as_ptr() as *mut () as usize;
+    address == usize::MAX
+}
+
+/// Helper type to allow accessing the reference counts without
+/// making any assertions about the data field.
+struct WeakInner<'a> {
+    weak: &'a Cell<usize>,
+    strong: &'a Cell<usize>,
+}
 
+impl<T: ?Sized> 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,
@@ -1854,21 +1868,7 @@ impl<T> Weak<T> {
         // SAFETY: we now have recovered the original Weak pointer, so can create the Weak.
         Weak { ptr: unsafe { NonNull::new_unchecked(ptr) } }
     }
-}
-
-pub(crate) fn is_dangling<T: ?Sized>(ptr: NonNull<T>) -> bool {
-    let address = ptr.as_ptr() as *mut () as usize;
-    address == usize::MAX
-}
-
-/// Helper type to allow accessing the reference counts without
-/// making any assertions about the data field.
-struct WeakInner<'a> {
-    weak: &'a Cell<usize>,
-    strong: &'a Cell<usize>,
-}
 
-impl<T: ?Sized> Weak<T> {
     /// Attempts to upgrade the `Weak` pointer to an [`Rc`], delaying
     /// dropping of the inner value if successful.
     ///