Skip to content

Commit fefcba7

Browse files
authored
Merge pull request #542 from pvdrz/clippy-fixes
Fix `clippy::nursery` warnings
2 parents 3c97d2f + d65abc2 commit fefcba7

File tree

11 files changed

+44
-37
lines changed

11 files changed

+44
-37
lines changed

src/binary_heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,14 @@ where
596596
}
597597
}
598598

599-
impl<'a, T, K, S> PeekMutInner<'a, T, K, S>
599+
impl<T, K, S> PeekMutInner<'_, T, K, S>
600600
where
601601
T: Ord,
602602
K: Kind,
603603
S: VecStorage<T> + ?Sized,
604604
{
605605
/// Removes the peeked value from the heap and returns it.
606-
pub fn pop(mut this: PeekMutInner<'a, T, K, S>) -> T {
606+
pub fn pop(mut this: Self) -> T {
607607
let value = this.heap.pop().unwrap();
608608
this.sift = false;
609609
value

src/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ where
946946
T: Clone,
947947
{
948948
fn clone(&self) -> Self {
949-
let mut res = Deque::new();
949+
let mut res = Self::new();
950950
for i in self {
951951
// safety: the original and new deques have the same capacity, so it can
952952
// not become full.

src/histbuf.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ pub struct OldestOrderedInner<'a, T, S: HistBufStorage<T> + ?Sized> {
587587
}
588588

589589
/// Double ended iterator on the underlying buffer ordered from the oldest data
590-
/// to the newest
590+
/// to the newest.
591+
///
591592
/// This type exists for backwards compatibility. It is always better to convert it to an [`OldestOrderedView`] with [`into_view`](OldestOrdered::into_view)
592593
pub type OldestOrdered<'a, T, const N: usize> =
593594
OldestOrderedInner<'a, T, OwnedHistBufStorage<T, N>>;

src/indexmap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct Pos {
9797

9898
impl Pos {
9999
fn new(index: usize, hash: HashValue) -> Self {
100-
Pos {
100+
Self {
101101
nz: unsafe {
102102
NonZeroU32::new_unchecked(
103103
((u32::from(hash.0) << 16) + index as u32).wrapping_add(1),
@@ -146,7 +146,7 @@ impl<K, V, const N: usize> CoreMap<K, V, N> {
146146
const fn new() -> Self {
147147
const INIT: Option<Pos> = None;
148148

149-
CoreMap {
149+
Self {
150150
entries: Vec::new(),
151151
indices: [INIT; N],
152152
}
@@ -733,7 +733,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
733733
crate::sealed::greater_than_1::<N>();
734734
crate::sealed::power_of_two::<N>();
735735

736-
IndexMap {
736+
Self {
737737
build_hasher: BuildHasherDefault::new(),
738738
core: CoreMap::new(),
739739
}
@@ -1240,7 +1240,7 @@ where
12401240
crate::sealed::greater_than_1::<N>();
12411241
crate::sealed::power_of_two::<N>();
12421242

1243-
IndexMap {
1243+
Self {
12441244
build_hasher: <_>::default(),
12451245
core: CoreMap::new(),
12461246
}
@@ -1309,7 +1309,7 @@ where
13091309
where
13101310
I: IntoIterator<Item = (K, V)>,
13111311
{
1312-
let mut map = IndexMap::default();
1312+
let mut map = Self::default();
13131313
map.extend(iterable);
13141314
map
13151315
}

src/indexset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct IndexSet<T, S, const N: usize> {
9191
impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N> {
9292
/// Creates an empty `IndexSet`
9393
pub const fn new() -> Self {
94-
IndexSet {
94+
Self {
9595
map: IndexMap::new(),
9696
}
9797
}
@@ -533,7 +533,7 @@ where
533533
S: Default,
534534
{
535535
fn default() -> Self {
536-
IndexSet {
536+
Self {
537537
map: <_>::default(),
538538
}
539539
}
@@ -586,7 +586,7 @@ where
586586
where
587587
I: IntoIterator<Item = T>,
588588
{
589-
let mut set = IndexSet::default();
589+
let mut set = Self::default();
590590
set.extend(iter);
591591
set
592592
}

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@
140140
),
141141
feature(integer_atomics)
142142
)]
143+
#![warn(
144+
clippy::use_self,
145+
clippy::too_long_first_doc_paragraph,
146+
clippy::redundant_pub_crate,
147+
clippy::option_if_let_else
148+
)]
143149

144150
pub use binary_heap::BinaryHeap;
145151
pub use deque::Deque;

src/pool/treiber/cas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ where
120120
}
121121

122122
#[inline]
123-
pub fn from_static_mut_ref(reference: &'static mut N) -> NonNullPtr<N> {
123+
pub fn from_static_mut_ref(reference: &'static mut N) -> Self {
124124
// SAFETY: `reference` is a static mutable reference, i.e. a valid pointer.
125125
unsafe { Self::new_unchecked(initial_tag(), NonNull::from(reference)) }
126126
}

src/sealed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
#[allow(dead_code, path_statements, clippy::no_effect)]
2-
pub(crate) const fn smaller_than<const N: usize, const MAX: usize>() {
2+
pub const fn smaller_than<const N: usize, const MAX: usize>() {
33
Assert::<N, MAX>::LESS;
44
}
55

66
#[allow(dead_code, path_statements, clippy::no_effect)]
7-
pub(crate) const fn greater_than_eq<const N: usize, const MIN: usize>() {
7+
pub const fn greater_than_eq<const N: usize, const MIN: usize>() {
88
Assert::<N, MIN>::GREATER_EQ;
99
}
1010

1111
#[allow(dead_code, path_statements, clippy::no_effect)]
12-
pub(crate) const fn greater_than_eq_0<const N: usize>() {
12+
pub const fn greater_than_eq_0<const N: usize>() {
1313
Assert::<N, 0>::GREATER_EQ;
1414
}
1515

1616
#[allow(dead_code, path_statements, clippy::no_effect)]
17-
pub(crate) const fn greater_than_0<const N: usize>() {
17+
pub const fn greater_than_0<const N: usize>() {
1818
Assert::<N, 0>::GREATER;
1919
}
2020

2121
#[allow(dead_code, path_statements, clippy::no_effect)]
22-
pub(crate) const fn greater_than_1<const N: usize>() {
22+
pub const fn greater_than_1<const N: usize>() {
2323
Assert::<N, 1>::GREATER;
2424
}
2525

2626
#[allow(dead_code, path_statements, clippy::no_effect)]
27-
pub(crate) const fn power_of_two<const N: usize>() {
27+
pub const fn power_of_two<const N: usize>() {
2828
Assert::<N, 0>::GREATER;
2929
Assert::<N, 0>::POWER_OF_TWO;
3030
}

src/spsc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ where
368368
T: Clone,
369369
{
370370
fn clone(&self) -> Self {
371-
let mut new: Queue<T, N> = Queue::new();
371+
let mut new: Self = Self::new();
372372

373373
for s in self.iter() {
374374
unsafe {
@@ -829,7 +829,7 @@ mod tests {
829829
unsafe {
830830
COUNT += 1;
831831
}
832-
Droppable
832+
Self
833833
}
834834
}
835835

src/string/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ impl<S: VecStorage<u8> + ?Sized> StringInner<S> {
581581
/// ```
582582
#[inline]
583583
pub fn remove(&mut self, index: usize) -> char {
584-
let ch = match self[index..].chars().next() {
585-
Some(ch) => ch,
586-
None => panic!("cannot remove a char from the end of a string"),
587-
};
584+
let ch = self[index..]
585+
.chars()
586+
.next()
587+
.unwrap_or_else(|| panic!("cannot remove a char from the end of a string"));
588588

589589
let next = index + ch.len_utf8();
590590
let len = self.len();
@@ -632,7 +632,7 @@ impl<const N: usize> Default for String<N> {
632632
impl<'a, const N: usize> TryFrom<&'a str> for String<N> {
633633
type Error = ();
634634
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
635-
let mut new = String::new();
635+
let mut new = Self::new();
636636
new.push_str(s)?;
637637
Ok(new)
638638
}
@@ -642,15 +642,15 @@ impl<const N: usize> str::FromStr for String<N> {
642642
type Err = ();
643643

644644
fn from_str(s: &str) -> Result<Self, Self::Err> {
645-
let mut new = String::new();
645+
let mut new = Self::new();
646646
new.push_str(s)?;
647647
Ok(new)
648648
}
649649
}
650650

651651
impl<const N: usize> iter::FromIterator<char> for String<N> {
652652
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
653-
let mut new = String::new();
653+
let mut new = Self::new();
654654
for c in iter {
655655
new.push(c).unwrap();
656656
}
@@ -660,7 +660,7 @@ impl<const N: usize> iter::FromIterator<char> for String<N> {
660660

661661
impl<'a, const N: usize> iter::FromIterator<&'a char> for String<N> {
662662
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
663-
let mut new = String::new();
663+
let mut new = Self::new();
664664
for c in iter {
665665
new.push(*c).unwrap();
666666
}
@@ -670,7 +670,7 @@ impl<'a, const N: usize> iter::FromIterator<&'a char> for String<N> {
670670

671671
impl<'a, const N: usize> iter::FromIterator<&'a str> for String<N> {
672672
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
673-
let mut new = String::new();
673+
let mut new = Self::new();
674674
for c in iter {
675675
new.push_str(c).unwrap();
676676
}
@@ -782,7 +782,7 @@ impl<S: VecStorage<u8> + ?Sized> PartialEq<&str> for StringInner<S> {
782782
impl<S: VecStorage<u8> + ?Sized> PartialEq<StringInner<S>> for str {
783783
#[inline]
784784
fn eq(&self, other: &StringInner<S>) -> bool {
785-
str::eq(self, &other[..])
785+
Self::eq(self, &other[..])
786786
}
787787
}
788788

src/vec/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<T, const N: usize> Vec<T, N> {
197197
where
198198
T: Clone,
199199
{
200-
let mut v = Vec::new();
200+
let mut v = Self::new();
201201
v.extend_from_slice(other)?;
202202
Ok(v)
203203
}
@@ -229,7 +229,7 @@ impl<T, const N: usize> Vec<T, N> {
229229
buffer: unsafe { mem::transmute_copy(&src) },
230230
}
231231
} else {
232-
let mut v = Vec::<T, N>::new();
232+
let mut v = Self::new();
233233

234234
for (src_elem, dst_elem) in src.iter().zip(v.buffer.buffer.iter_mut()) {
235235
// 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<T, N> {
12221222
type Error = ();
12231223

12241224
fn try_from(slice: &'a [T]) -> Result<Self, Self::Error> {
1225-
Vec::from_slice(slice)
1225+
Self::from_slice(slice)
12261226
}
12271227
}
12281228

@@ -1279,7 +1279,7 @@ impl<T, const N: usize> FromIterator<T> for Vec<T, N> {
12791279
where
12801280
I: IntoIterator<Item = T>,
12811281
{
1282-
let mut vec = Vec::new();
1282+
let mut vec = Self::new();
12831283
for i in iter {
12841284
vec.push(i).ok().expect("Vec::from_iter overflow");
12851285
}
@@ -1509,14 +1509,14 @@ impl<T, S: VecStorage<T> + ?Sized> borrow::BorrowMut<[T]> for VecInner<T, S> {
15091509
}
15101510
}
15111511

1512-
impl<T, S: VecStorage<T> + ?Sized> AsRef<VecInner<T, S>> for VecInner<T, S> {
1512+
impl<T, S: VecStorage<T> + ?Sized> AsRef<Self> for VecInner<T, S> {
15131513
#[inline]
15141514
fn as_ref(&self) -> &Self {
15151515
self
15161516
}
15171517
}
15181518

1519-
impl<T, S: VecStorage<T> + ?Sized> AsMut<VecInner<T, S>> for VecInner<T, S> {
1519+
impl<T, S: VecStorage<T> + ?Sized> AsMut<Self> for VecInner<T, S> {
15201520
#[inline]
15211521
fn as_mut(&mut self) -> &mut Self {
15221522
self

0 commit comments

Comments
 (0)