From e3e07b796b3ceaa2f0841e1132be41e12f5d4a3b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 24 Mar 2025 11:25:57 -0500 Subject: [PATCH] Fix `clippy::use_self` warnings --- src/binary_heap.rs | 4 ++-- src/deque.rs | 2 +- src/indexmap.rs | 10 +++++----- src/indexset.rs | 6 +++--- src/lib.rs | 1 + src/pool/treiber/cas.rs | 2 +- src/spsc.rs | 4 ++-- src/string/mod.rs | 12 ++++++------ src/vec/mod.rs | 12 ++++++------ 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/binary_heap.rs b/src/binary_heap.rs index 00deebc6..a67a967d 100644 --- a/src/binary_heap.rs +++ b/src/binary_heap.rs @@ -596,14 +596,14 @@ where } } -impl<'a, T, K, S> PeekMutInner<'a, T, K, S> +impl PeekMutInner<'_, T, K, S> where T: Ord, K: Kind, S: VecStorage + ?Sized, { /// Removes the peeked value from the heap and returns it. - pub fn pop(mut this: PeekMutInner<'a, T, K, S>) -> T { + pub fn pop(mut this: Self) -> T { let value = this.heap.pop().unwrap(); this.sift = false; value diff --git a/src/deque.rs b/src/deque.rs index a9044158..fcc0331c 100644 --- a/src/deque.rs +++ b/src/deque.rs @@ -946,7 +946,7 @@ where T: Clone, { fn clone(&self) -> Self { - let mut res = Deque::new(); + let mut res = Self::new(); for i in self { // safety: the original and new deques have the same capacity, so it can // not become full. diff --git a/src/indexmap.rs b/src/indexmap.rs index ebdf1862..ca36f192 100644 --- a/src/indexmap.rs +++ b/src/indexmap.rs @@ -97,7 +97,7 @@ pub struct Pos { impl Pos { fn new(index: usize, hash: HashValue) -> Self { - Pos { + Self { nz: unsafe { NonZeroU32::new_unchecked( ((u32::from(hash.0) << 16) + index as u32).wrapping_add(1), @@ -146,7 +146,7 @@ impl CoreMap { const fn new() -> Self { const INIT: Option = None; - CoreMap { + Self { entries: Vec::new(), indices: [INIT; N], } @@ -733,7 +733,7 @@ impl IndexMap, N> { crate::sealed::greater_than_1::(); crate::sealed::power_of_two::(); - IndexMap { + Self { build_hasher: BuildHasherDefault::new(), core: CoreMap::new(), } @@ -1240,7 +1240,7 @@ where crate::sealed::greater_than_1::(); crate::sealed::power_of_two::(); - IndexMap { + Self { build_hasher: <_>::default(), core: CoreMap::new(), } @@ -1309,7 +1309,7 @@ where where I: IntoIterator, { - let mut map = IndexMap::default(); + let mut map = Self::default(); map.extend(iterable); map } diff --git a/src/indexset.rs b/src/indexset.rs index 89aae894..1a322d46 100644 --- a/src/indexset.rs +++ b/src/indexset.rs @@ -91,7 +91,7 @@ pub struct IndexSet { impl IndexSet, N> { /// Creates an empty `IndexSet` pub const fn new() -> Self { - IndexSet { + Self { map: IndexMap::new(), } } @@ -533,7 +533,7 @@ where S: Default, { fn default() -> Self { - IndexSet { + Self { map: <_>::default(), } } @@ -586,7 +586,7 @@ where where I: IntoIterator, { - let mut set = IndexSet::default(); + let mut set = Self::default(); set.extend(iter); set } diff --git a/src/lib.rs b/src/lib.rs index 3646e31c..47532973 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,6 +140,7 @@ ), feature(integer_atomics) )] +#![warn(clippy::use_self)] pub use binary_heap::BinaryHeap; pub use deque::Deque; diff --git a/src/pool/treiber/cas.rs b/src/pool/treiber/cas.rs index 8d3328a6..ab426c05 100644 --- a/src/pool/treiber/cas.rs +++ b/src/pool/treiber/cas.rs @@ -120,7 +120,7 @@ where } #[inline] - pub fn from_static_mut_ref(reference: &'static mut N) -> NonNullPtr { + pub fn from_static_mut_ref(reference: &'static mut N) -> Self { // SAFETY: `reference` is a static mutable reference, i.e. a valid pointer. unsafe { Self::new_unchecked(initial_tag(), NonNull::from(reference)) } } diff --git a/src/spsc.rs b/src/spsc.rs index 24299218..7f156813 100644 --- a/src/spsc.rs +++ b/src/spsc.rs @@ -368,7 +368,7 @@ where T: Clone, { fn clone(&self) -> Self { - let mut new: Queue = Queue::new(); + let mut new: Self = Self::new(); for s in self.iter() { unsafe { @@ -829,7 +829,7 @@ mod tests { unsafe { COUNT += 1; } - Droppable + Self } } diff --git a/src/string/mod.rs b/src/string/mod.rs index 238ea23d..590ded49 100644 --- a/src/string/mod.rs +++ b/src/string/mod.rs @@ -632,7 +632,7 @@ impl Default for String { impl<'a, const N: usize> TryFrom<&'a str> for String { type Error = (); fn try_from(s: &'a str) -> Result { - let mut new = String::new(); + let mut new = Self::new(); new.push_str(s)?; Ok(new) } @@ -642,7 +642,7 @@ impl str::FromStr for String { type Err = (); fn from_str(s: &str) -> Result { - let mut new = String::new(); + let mut new = Self::new(); new.push_str(s)?; Ok(new) } @@ -650,7 +650,7 @@ impl str::FromStr for String { impl iter::FromIterator for String { fn from_iter>(iter: T) -> Self { - let mut new = String::new(); + let mut new = Self::new(); for c in iter { new.push(c).unwrap(); } @@ -660,7 +660,7 @@ impl iter::FromIterator for String { impl<'a, const N: usize> iter::FromIterator<&'a char> for String { fn from_iter>(iter: T) -> Self { - let mut new = String::new(); + let mut new = Self::new(); for c in iter { new.push(*c).unwrap(); } @@ -670,7 +670,7 @@ impl<'a, const N: usize> iter::FromIterator<&'a char> for String { impl<'a, const N: usize> iter::FromIterator<&'a str> for String { fn from_iter>(iter: T) -> Self { - let mut new = String::new(); + let mut new = Self::new(); for c in iter { new.push_str(c).unwrap(); } @@ -782,7 +782,7 @@ impl + ?Sized> PartialEq<&str> for StringInner { impl + ?Sized> PartialEq> for str { #[inline] fn eq(&self, other: &StringInner) -> bool { - str::eq(self, &other[..]) + Self::eq(self, &other[..]) } } diff --git a/src/vec/mod.rs b/src/vec/mod.rs index fdc30857..d9b39268 100644 --- a/src/vec/mod.rs +++ b/src/vec/mod.rs @@ -197,7 +197,7 @@ impl Vec { where T: Clone, { - let mut v = Vec::new(); + let mut v = Self::new(); v.extend_from_slice(other)?; Ok(v) } @@ -229,7 +229,7 @@ impl Vec { buffer: unsafe { mem::transmute_copy(&src) }, } } else { - let mut v = Vec::::new(); + let mut v = Self::new(); for (src_elem, dst_elem) in src.iter().zip(v.buffer.buffer.iter_mut()) { // NOTE(unsafe) src element is not going to drop as src itself @@ -1222,7 +1222,7 @@ impl<'a, T: Clone, const N: usize> TryFrom<&'a [T]> for Vec { type Error = (); fn try_from(slice: &'a [T]) -> Result { - Vec::from_slice(slice) + Self::from_slice(slice) } } @@ -1279,7 +1279,7 @@ impl FromIterator for Vec { where I: IntoIterator, { - let mut vec = Vec::new(); + let mut vec = Self::new(); for i in iter { vec.push(i).ok().expect("Vec::from_iter overflow"); } @@ -1509,14 +1509,14 @@ impl + ?Sized> borrow::BorrowMut<[T]> for VecInner { } } -impl + ?Sized> AsRef> for VecInner { +impl + ?Sized> AsRef for VecInner { #[inline] fn as_ref(&self) -> &Self { self } } -impl + ?Sized> AsMut> for VecInner { +impl + ?Sized> AsMut for VecInner { #[inline] fn as_mut(&mut self) -> &mut Self { self