@@ -331,6 +331,33 @@ impl<T: ?Sized> Arc<T> {
331331 deallocate ( ptr as * mut u8 , size_of_val ( & * ptr) , align_of_val ( & * ptr) )
332332 }
333333 }
334+
335+ #[ inline]
336+ #[ unstable( feature = "ptr_eq" ,
337+ reason = "newly added" ,
338+ issue = "36497" ) ]
339+ /// Return whether two `Arc` references point to the same value
340+ /// (not just values that compare equal).
341+ ///
342+ /// # Examples
343+ ///
344+ /// ```
345+ /// #![feature(ptr_eq)]
346+ ///
347+ /// use std::sync::Arc;
348+ ///
349+ /// let five = Arc::new(5);
350+ /// let same_five = five.clone();
351+ /// let other_five = Arc::new(5);
352+ ///
353+ /// assert!(Arc::ptr_eq(&five, &same_five));
354+ /// assert!(!Arc::ptr_eq(&five, &other_five));
355+ /// ```
356+ pub fn ptr_eq ( this : & Self , other : & Self ) -> bool {
357+ let this_ptr: * const ArcInner < T > = * this. ptr ;
358+ let other_ptr: * const ArcInner < T > = * other. ptr ;
359+ this_ptr == other_ptr
360+ }
334361}
335362
336363#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1200,6 +1227,16 @@ mod tests {
12001227 let foo: Weak < usize > = Weak :: new ( ) ;
12011228 assert ! ( foo. upgrade( ) . is_none( ) ) ;
12021229 }
1230+
1231+ #[ test]
1232+ fn test_ptr_eq ( ) {
1233+ let five = Arc :: new ( 5 ) ;
1234+ let same_five = five. clone ( ) ;
1235+ let other_five = Arc :: new ( 5 ) ;
1236+
1237+ assert ! ( Arc :: ptr_eq( & five, & same_five) ) ;
1238+ assert ! ( !Arc :: ptr_eq( & five, & other_five) ) ;
1239+ }
12031240}
12041241
12051242#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments