Skip to content

Commit

Permalink
Allow ambiguous_wide_pointer_comparisons lint for std methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Dec 6, 2023
1 parent 6856a86 commit 30c7b18
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,7 @@ impl<T> *const [T] {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> PartialEq for *const T {
#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn eq(&self, other: &*const T) -> bool {
*self == *other
}
Expand All @@ -1777,6 +1778,7 @@ impl<T: ?Sized> Eq for *const T {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Ord for *const T {
#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn cmp(&self, other: &*const T) -> Ordering {
if self < other {
Less
Expand All @@ -1796,21 +1798,25 @@ impl<T: ?Sized> PartialOrd for *const T {
}

#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn lt(&self, other: &*const T) -> bool {
*self < *other
}

#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn le(&self, other: &*const T) -> bool {
*self <= *other
}

#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn gt(&self, other: &*const T) -> bool {
*self > *other
}

#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn ge(&self, other: &*const T) -> bool {
*self >= *other
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,7 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
#[inline(always)]
#[must_use = "pointer comparison produces a value"]
#[rustc_diagnostic_item = "ptr_eq"]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))] // it's actually clear here
pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
a == b
}
Expand Down
6 changes: 6 additions & 0 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,7 @@ impl<T> *mut [T] {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> PartialEq for *mut T {
#[inline(always)]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn eq(&self, other: &*mut T) -> bool {
*self == *other
}
Expand All @@ -2200,6 +2201,7 @@ impl<T: ?Sized> Eq for *mut T {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Ord for *mut T {
#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn cmp(&self, other: &*mut T) -> Ordering {
if self < other {
Less
Expand All @@ -2219,21 +2221,25 @@ impl<T: ?Sized> PartialOrd for *mut T {
}

#[inline(always)]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn lt(&self, other: &*mut T) -> bool {
*self < *other
}

#[inline(always)]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn le(&self, other: &*mut T) -> bool {
*self <= *other
}

#[inline(always)]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn gt(&self, other: &*mut T) -> bool {
*self > *other
}

#[inline(always)]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn ge(&self, other: &*mut T) -> bool {
*self >= *other
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ impl<T: ?Sized> Eq for NonNull<T> {}
#[stable(feature = "nonnull", since = "1.25.0")]
impl<T: ?Sized> PartialEq for NonNull<T> {
#[inline]
#[cfg_attr(not(bootstrap), allow(ambiguous_wide_pointer_comparisons))]
fn eq(&self, other: &Self) -> bool {
self.as_ptr() == other.as_ptr()
}
Expand Down

0 comments on commit 30c7b18

Please sign in to comment.