From 88eb2c1aefc578178a2d99a1fb6a6657cca21f85 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Wed, 2 Nov 2022 14:34:35 +0200 Subject: [PATCH] Remove `ptr::eq()` from `Cell::swap()` It looks redundant to me, since we use `ptr::swap()` and not `swap_nonoverlapping()` so even if they are the same cell it's fine, no? I think we could also leave the comparison and use `swap_nonoverlapping()` but I'm less sure about that, since maybe we have a valid way to obtain partially overlapping cells? I can't think of such way, but I am not sure. --- library/core/src/cell.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 7bf32cb0d98f2..e31de08f7622b 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -381,9 +381,6 @@ impl Cell { #[inline] #[stable(feature = "move_cell", since = "1.17.0")] pub fn swap(&self, other: &Self) { - if ptr::eq(self, other) { - return; - } // SAFETY: This can be risky if called from separate threads, but `Cell` // is `!Sync` so this won't happen. This also won't invalidate any // pointers since `Cell` makes sure nothing else will be pointing into