@@ -1130,6 +1130,53 @@ impl<T: ?Sized> Weak<T> {
11301130 Some ( unsafe { self . ptr . as_ref ( ) } )
11311131 }
11321132 }
1133+
1134+ /// Returns true if the two `Weak`s point to the same value (not just values
1135+ /// that compare as equal).
1136+ ///
1137+ /// # Notes
1138+ ///
1139+ /// Since this compares pointers it means that `Weak::new()` will equal each
1140+ /// other, even though they don't point to any value.
1141+ ///
1142+ ///
1143+ /// # Examples
1144+ ///
1145+ /// ```
1146+ /// #![feature(weak_ptr_eq)]
1147+ /// use std::sync::{Arc, Weak};
1148+ ///
1149+ /// let first_rc = Arc::new(5);
1150+ /// let first = Arc::downgrade(&first_rc);
1151+ /// let second = Arc::downgrade(&first_rc);
1152+ ///
1153+ /// assert!(Weak::ptr_eq(&first, &second));
1154+ ///
1155+ /// let third_rc = Arc::new(5);
1156+ /// let third = Arc::downgrade(&third_rc);
1157+ ///
1158+ /// assert!(!Weak::ptr_eq(&first, &third));
1159+ /// ```
1160+ ///
1161+ /// Comparing `Weak::new`.
1162+ ///
1163+ /// ```
1164+ /// #![feature(weak_ptr_eq)]
1165+ /// use std::sync::{Arc, Weak};
1166+ ///
1167+ /// let first = Weak::new();
1168+ /// let second = Weak::new();
1169+ /// assert!(Weak::ptr_eq(&first, &second));
1170+ ///
1171+ /// let third_rc = Arc::new(());
1172+ /// let third = Arc::downgrade(&third_rc);
1173+ /// assert!(!Weak::ptr_eq(&first, &third));
1174+ /// ```
1175+ #[ inline]
1176+ #[ unstable( feature = "weak_ptr_eq" , issue = "55981" ) ]
1177+ pub fn ptr_eq ( this : & Self , other : & Self ) -> bool {
1178+ this. ptr . as_ptr ( ) == other. ptr . as_ptr ( )
1179+ }
11331180}
11341181
11351182#[ stable( feature = "arc_weak" , since = "1.4.0" ) ]
0 commit comments