diff --git a/src/binary_heap.rs b/src/binary_heap.rs index 00deebc65b..a67a967d16 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 a9044158aa..fcc0331c7c 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/histbuf.rs b/src/histbuf.rs index cf152db745..3ce9aa55fc 100644 --- a/src/histbuf.rs +++ b/src/histbuf.rs @@ -587,7 +587,8 @@ pub struct OldestOrderedInner<'a, T, S: HistBufStorage + ?Sized> { } /// Double ended iterator on the underlying buffer ordered from the oldest data -/// to the newest +/// to the newest. +/// /// This type exists for backwards compatibility. It is always better to convert it to an [`OldestOrderedView`] with [`into_view`](OldestOrdered::into_view) pub type OldestOrdered<'a, T, const N: usize> = OldestOrderedInner<'a, T, OwnedHistBufStorage>; diff --git a/src/indexmap.rs b/src/indexmap.rs index ebdf186219..ca36f19254 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 89aae8942b..1a322d4659 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 3646e31c6a..523598c9d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,6 +140,12 @@ ), feature(integer_atomics) )] +#![warn( + clippy::use_self, + clippy::too_long_first_doc_paragraph, + clippy::redundant_pub_crate, + clippy::option_if_let_else +)] pub use binary_heap::BinaryHeap; pub use deque::Deque; diff --git a/src/pool/treiber/cas.rs b/src/pool/treiber/cas.rs index 8d3328a6aa..ab426c0571 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/sealed.rs b/src/sealed.rs index 5e4ef4bba4..ca0b8ec125 100644 --- a/src/sealed.rs +++ b/src/sealed.rs @@ -1,30 +1,30 @@ #[allow(dead_code, path_statements, clippy::no_effect)] -pub(crate) const fn smaller_than() { +pub const fn smaller_than() { Assert::::LESS; } #[allow(dead_code, path_statements, clippy::no_effect)] -pub(crate) const fn greater_than_eq() { +pub const fn greater_than_eq() { Assert::::GREATER_EQ; } #[allow(dead_code, path_statements, clippy::no_effect)] -pub(crate) const fn greater_than_eq_0() { +pub const fn greater_than_eq_0() { Assert::::GREATER_EQ; } #[allow(dead_code, path_statements, clippy::no_effect)] -pub(crate) const fn greater_than_0() { +pub const fn greater_than_0() { Assert::::GREATER; } #[allow(dead_code, path_statements, clippy::no_effect)] -pub(crate) const fn greater_than_1() { +pub const fn greater_than_1() { Assert::::GREATER; } #[allow(dead_code, path_statements, clippy::no_effect)] -pub(crate) const fn power_of_two() { +pub const fn power_of_two() { Assert::::GREATER; Assert::::POWER_OF_TWO; } diff --git a/src/spsc.rs b/src/spsc.rs index 242992181d..7f15681397 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 238ea23d5d..962d8f56e6 100644 --- a/src/string/mod.rs +++ b/src/string/mod.rs @@ -581,10 +581,10 @@ impl + ?Sized> StringInner { /// ``` #[inline] pub fn remove(&mut self, index: usize) -> char { - let ch = match self[index..].chars().next() { - Some(ch) => ch, - None => panic!("cannot remove a char from the end of a string"), - }; + let ch = self[index..] + .chars() + .next() + .unwrap_or_else(|| panic!("cannot remove a char from the end of a string")); let next = index + ch.len_utf8(); let len = self.len(); @@ -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 fdc308577a..d9b3926860 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