Skip to content

Commit 08908de

Browse files
committed
rust: clean Rust 1.87.0's clippy::ptr_eq lints
Starting with Rust 1.87.0 (expected 2025-05-15) [1], Clippy may expand the `ptr_eq` lint, e.g.: error: use `core::ptr::eq` when comparing raw pointers --> rust/kernel/list.rs:438:12 | 438 | if self.first == item { | ^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::eq(self.first, item)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq = note: `-D clippy::ptr-eq` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]` Thus clean the few cases we have. This patch may not be actually needed by the time Rust 1.87.0 releases since a PR to relax the lint has been beta nominated [2] due to reports of being too eager (at least by default) [3]. Cc: [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs). Link: rust-lang/rust-clippy#14339 [1] Link: rust-lang/rust-clippy#14526 [2] Link: rust-lang/rust-clippy#14525 [3] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent f911d0a commit 08908de

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

rust/kernel/alloc/kvec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ where
743743
pub fn collect(self, flags: Flags) -> Vec<T, A> {
744744
let old_layout = self.layout;
745745
let (mut ptr, buf, len, mut cap) = self.into_raw_parts();
746-
let has_advanced = ptr != buf.as_ptr();
746+
let has_advanced = !core::ptr::eq(ptr, buf.as_ptr());
747747

748748
if has_advanced {
749749
// Copy the contents we have advanced to at the beginning of the buffer.

rust/kernel/list.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl<T: ?Sized + ListItem<ID>, const ID: u64> List<T, ID> {
435435
// * If `item` was the only item in the list, then `prev == item`, and we just set
436436
// `item->next` to null, so this correctly sets `first` to null now that the list is
437437
// empty.
438-
if self.first == item {
438+
if core::ptr::eq(self.first, item) {
439439
// SAFETY: The `prev` pointer is the value that `item->prev` had when it was in this
440440
// list, so it must be valid. There is no race since `prev` is still in the list and we
441441
// still have exclusive access to the list.
@@ -556,7 +556,7 @@ impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> Iterator for Iter<'a, T, ID> {
556556
let next = unsafe { (*current).next };
557557
// INVARIANT: If `current` was the last element of the list, then this updates it to null.
558558
// Otherwise, we update it to the next element.
559-
self.current = if next != self.stop {
559+
self.current = if !core::ptr::eq(next, self.stop) {
560560
next
561561
} else {
562562
ptr::null_mut()
@@ -726,7 +726,7 @@ impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> Cursor<'a, T, ID> {
726726
fn prev_ptr(&self) -> *mut ListLinksFields {
727727
let mut next = self.next;
728728
let first = self.list.first;
729-
if next == first {
729+
if core::ptr::eq(next, first) {
730730
// We are before the first element.
731731
return core::ptr::null_mut();
732732
}
@@ -788,7 +788,7 @@ impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> Cursor<'a, T, ID> {
788788
// access the `next` field.
789789
let mut next = unsafe { (*self.next).next };
790790

791-
if next == self.list.first {
791+
if core::ptr::eq(next, self.list.first) {
792792
next = core::ptr::null_mut();
793793
}
794794

@@ -802,7 +802,7 @@ impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> Cursor<'a, T, ID> {
802802
/// If the cursor is before the first element, then this call does nothing. This call returns
803803
/// `true` if the cursor's position was changed.
804804
pub fn move_prev(&mut self) -> bool {
805-
if self.next == self.list.first {
805+
if core::ptr::eq(self.next, self.list.first) {
806806
return false;
807807
}
808808

@@ -822,7 +822,7 @@ impl<'a, T: ?Sized + ListItem<ID>, const ID: u64> Cursor<'a, T, ID> {
822822
// * `ptr` is an element in the list or null.
823823
// * if `ptr` is null, then `self.list.first` is null so the list is empty.
824824
let item = unsafe { self.list.insert_inner(item, ptr) };
825-
if self.next == self.list.first {
825+
if core::ptr::eq(self.next, self.list.first) {
826826
// INVARIANT: We just inserted `item`, so it's a member of list.
827827
self.list.first = item;
828828
}

0 commit comments

Comments
 (0)