@@ -331,6 +331,33 @@ impl<T: ?Sized> Arc<T> {
331
331
deallocate ( ptr as * mut u8 , size_of_val ( & * ptr) , align_of_val ( & * ptr) )
332
332
}
333
333
}
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
+ }
334
361
}
335
362
336
363
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1200,6 +1227,16 @@ mod tests {
1200
1227
let foo: Weak < usize > = Weak :: new ( ) ;
1201
1228
assert ! ( foo. upgrade( ) . is_none( ) ) ;
1202
1229
}
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
+ }
1203
1240
}
1204
1241
1205
1242
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments