File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1868,6 +1868,28 @@ pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
18681868 a == b
18691869}
18701870
1871+ /// Compares the *addresses* of the two pointers for equality,
1872+ /// ignoring any metadata in fat pointers.
1873+ ///
1874+ /// If the arguments are thin pointers of the same type,
1875+ /// then this is the same as [`eq`].
1876+ ///
1877+ /// # Examples
1878+ ///
1879+ /// ```
1880+ /// #![feature(ptr_addr_eq)]
1881+ ///
1882+ /// let whole: &[i32; 3] = &[1, 2, 3];
1883+ /// let first: &i32 = &whole[0];
1884+ /// assert!(std::ptr::addr_eq(whole, first));
1885+ /// assert!(!std::ptr::eq::<dyn std::fmt::Debug>(whole, first));
1886+ /// ```
1887+ #[ unstable( feature = "ptr_addr_eq" , issue = "116324" ) ]
1888+ #[ inline( always) ]
1889+ pub fn addr_eq < T : ?Sized , U : ?Sized > ( p : * const T , q : * const U ) -> bool {
1890+ ( p as * const ( ) ) == ( q as * const ( ) )
1891+ }
1892+
18711893/// Hash a raw pointer.
18721894///
18731895/// This can be used to hash a `&T` reference (which coerces to `*const T` implicitly)
You can’t perform that action at this time.
0 commit comments