Rollup merge of #116351 - asquared31415:ptr_eq_must_use, r=workingjubilee

Add `must_use` on pointer equality functions

`ptr == ptr` (like all use of `==`) has a similar warning, and these functions are simple convenience wrappers over that.
This commit is contained in:
Matthias Krüger 2023-10-03 08:58:49 +02:00 committed by GitHub
commit cebe393a4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1864,6 +1864,7 @@ pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
/// ```
#[stable(feature = "ptr_eq", since = "1.17.0")]
#[inline(always)]
#[must_use = "pointer comparison produces a value"]
pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
a == b
}
@ -1886,6 +1887,7 @@ pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
/// ```
#[unstable(feature = "ptr_addr_eq", issue = "116324")]
#[inline(always)]
#[must_use = "pointer comparison produces a value"]
pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool {
(p as *const ()) == (q as *const ())
}