Skip to content

Commit

Permalink
Rollup merge of #116351 - asquared31415:ptr_eq_must_use, r=workingjub…
Browse files Browse the repository at this point in the history
…ilee

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.
  • Loading branch information
matthiaskrgr committed Oct 3, 2023
2 parents 634e5c9 + 34ea540 commit cebe393
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,7 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
/// ```
#[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
}
Expand All @@ -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 ())
}
Expand Down

0 comments on commit cebe393

Please sign in to comment.