Skip to content

Commit 2d9e930

Browse files
authored
Merge pull request #4 from cuviper/clippy
Fix `clippy::needless_lifetimes` and `clippy::type_complexity`
2 parents 6786696 + 1b175de commit 2d9e930

File tree

7 files changed

+74
-70
lines changed

7 files changed

+74
-70
lines changed

src/map/core.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ fn update_index(table: &mut Indices, offset: usize, hash: HashValue, old: usize,
102102
*index = OffsetIndex::new(new, offset);
103103
}
104104

105+
/// A simple alias to help `clippy::type_complexity`
106+
type Pair<T> = (T, T);
107+
105108
#[inline]
106-
fn len_slices<T>((head, tail): (&[T], &[T])) -> usize {
109+
fn len_slices<T>((head, tail): Pair<&[T]>) -> usize {
107110
head.len() + tail.len()
108111
}
109112

110113
#[inline]
111-
fn iter_slices<'a, T>(
112-
(head, tail): (&'a [T], &'a [T]),
113-
) -> iter::Chain<slice::Iter<'a, T>, slice::Iter<'a, T>> {
114+
fn iter_slices<T>(
115+
(head, tail): Pair<&'_ [T]>,
116+
) -> iter::Chain<slice::Iter<'_, T>, slice::Iter<'_, T>> {
114117
head.iter().chain(tail)
115118
}
116119

117120
#[inline]
118-
fn split_slices<'a, T>(
119-
(head, tail): (&'a [T], &'a [T]),
120-
i: usize,
121-
) -> ((&'a [T], &'a [T]), (&'a [T], &'a [T])) {
121+
fn split_slices<T>((head, tail): Pair<&'_ [T]>, i: usize) -> Pair<Pair<&'_ [T]>> {
122122
if i <= head.len() {
123123
let (head, mid) = head.split_at(i);
124124
((head, &[]), (mid, tail))
@@ -129,10 +129,7 @@ fn split_slices<'a, T>(
129129
}
130130

131131
#[inline]
132-
fn split_slices_mut<'a, T>(
133-
(head, tail): (&'a mut [T], &'a mut [T]),
134-
i: usize,
135-
) -> ((&'a mut [T], &'a mut [T]), (&'a mut [T], &'a mut [T])) {
132+
fn split_slices_mut<T>((head, tail): Pair<&'_ mut [T]>, i: usize) -> Pair<Pair<&'_ mut [T]>> {
136133
if i <= head.len() {
137134
let (head, mid) = head.split_at_mut(i);
138135
((head, &mut []), (mid, tail))
@@ -143,11 +140,7 @@ fn split_slices_mut<'a, T>(
143140
}
144141

145142
#[inline]
146-
fn sub_slices_mut<'a, T>(
147-
slices: (&'a mut [T], &'a mut [T]),
148-
start: usize,
149-
end: usize,
150-
) -> (&'a mut [T], &'a mut [T]) {
143+
fn sub_slices_mut<T>(slices: Pair<&'_ mut [T]>, start: usize, end: usize) -> Pair<&'_ mut [T]> {
151144
let (slices, _) = split_slices_mut(slices, end);
152145
split_slices_mut(slices, start).1
153146
}
@@ -156,11 +149,7 @@ fn sub_slices_mut<'a, T>(
156149
/// and without regard for duplication.
157150
///
158151
/// ***Panics*** if there is not sufficient capacity already.
159-
fn insert_bulk_no_grow<K, V>(
160-
indices: &mut Indices,
161-
offset: usize,
162-
entries: (&[Bucket<K, V>], &[Bucket<K, V>]),
163-
) {
152+
fn insert_bulk_no_grow<K, V>(indices: &mut Indices, offset: usize, entries: Pair<&[Bucket<K, V>]>) {
164153
assert!(indices.capacity() - indices.len() >= len_slices(entries));
165154
for entry in iter_slices(entries) {
166155
let index = OffsetIndex::new(indices.len(), offset);

src/map/iter.rs

+32-25
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ pub(crate) struct Buckets<'a, K, V> {
4343

4444
impl<'a, K, V> Buckets<'a, K, V> {
4545
pub(crate) fn new(entries: &'a VecDeque<Bucket<K, V>>) -> Self {
46-
Self::from_slices(entries.as_slices())
47-
}
48-
49-
pub(crate) fn from_slices((head, tail): (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
46+
let (head, tail) = entries.as_slices();
5047
Self {
5148
head: head.iter(),
5249
tail: tail.iter(),
5350
}
5451
}
52+
53+
pub(crate) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
54+
Self {
55+
head: slice.iter(),
56+
tail: [].iter(),
57+
}
58+
}
5559
}
5660

5761
impl<'a, K, V> Iterator for Buckets<'a, K, V> {
@@ -148,18 +152,25 @@ struct BucketsMut<'a, K, V> {
148152

149153
impl<'a, K, V> BucketsMut<'a, K, V> {
150154
fn new(entries: &'a mut VecDeque<Bucket<K, V>>) -> Self {
151-
Self::from_mut_slices(entries.as_mut_slices())
152-
}
153-
154-
fn from_mut_slices((head, tail): (&'a mut [Bucket<K, V>], &'a mut [Bucket<K, V>])) -> Self {
155+
let (head, tail) = entries.as_mut_slices();
155156
Self {
156157
head: head.iter_mut(),
157158
tail: tail.iter_mut(),
158159
}
159160
}
160161

162+
fn from_mut_slice(slice: &'a mut [Bucket<K, V>]) -> Self {
163+
Self {
164+
head: slice.iter_mut(),
165+
tail: [].iter_mut(),
166+
}
167+
}
168+
161169
fn iter(&self) -> Buckets<'_, K, V> {
162-
Buckets::from_slices((self.head.as_slice(), self.tail.as_slice()))
170+
Buckets {
171+
head: self.head.as_slice().iter(),
172+
tail: self.tail.as_slice().iter(),
173+
}
163174
}
164175
}
165176

@@ -255,9 +266,9 @@ impl<'a, K, V> Iter<'a, K, V> {
255266
}
256267
}
257268

258-
pub(super) fn from_slices(slices: (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
269+
pub(super) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
259270
Self {
260-
iter: Buckets::from_slices(slices),
271+
iter: Buckets::from_slice(slice),
261272
}
262273
}
263274
}
@@ -318,11 +329,9 @@ impl<'a, K, V> IterMut<'a, K, V> {
318329
}
319330
}
320331

321-
pub(super) fn from_mut_slices(
322-
slices: (&'a mut [Bucket<K, V>], &'a mut [Bucket<K, V>]),
323-
) -> Self {
332+
pub(super) fn from_mut_slice(slice: &'a mut [Bucket<K, V>]) -> Self {
324333
Self {
325-
iter: BucketsMut::from_mut_slices(slices),
334+
iter: BucketsMut::from_mut_slice(slice),
326335
}
327336
}
328337
}
@@ -517,9 +526,9 @@ impl<'a, K, V> Keys<'a, K, V> {
517526
}
518527
}
519528

520-
pub(super) fn from_slices(slices: (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
529+
pub(super) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
521530
Self {
522-
iter: Buckets::from_slices(slices),
531+
iter: Buckets::from_slice(slice),
523532
}
524533
}
525534
}
@@ -623,7 +632,7 @@ impl<K, V> Default for Keys<'_, K, V> {
623632
/// map.insert("foo", 1);
624633
/// println!("{:?}", map.keys()[10]); // panics!
625634
/// ```
626-
impl<'a, K, V> Index<usize> for Keys<'a, K, V> {
635+
impl<K, V> Index<usize> for Keys<'_, K, V> {
627636
type Output = K;
628637

629638
/// Returns a reference to the key at the supplied `index`.
@@ -705,9 +714,9 @@ impl<'a, K, V> Values<'a, K, V> {
705714
}
706715
}
707716

708-
pub(super) fn from_slices(slices: (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
717+
pub(super) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
709718
Self {
710-
iter: Buckets::from_slices(slices),
719+
iter: Buckets::from_slice(slice),
711720
}
712721
}
713722
}
@@ -768,11 +777,9 @@ impl<'a, K, V> ValuesMut<'a, K, V> {
768777
}
769778
}
770779

771-
pub(super) fn from_mut_slices(
772-
slices: (&'a mut [Bucket<K, V>], &'a mut [Bucket<K, V>]),
773-
) -> Self {
780+
pub(super) fn from_mut_slice(slice: &'a mut [Bucket<K, V>]) -> Self {
774781
Self {
775-
iter: BucketsMut::from_mut_slices(slices),
782+
iter: BucketsMut::from_mut_slice(slice),
776783
}
777784
}
778785
}
@@ -975,7 +982,7 @@ where
975982
{
976983
}
977984

978-
impl<'a, I, K, V, S> fmt::Debug for Splice<'a, I, K, V, S>
985+
impl<I, K, V, S> fmt::Debug for Splice<'_, I, K, V, S>
979986
where
980987
I: fmt::Debug + Iterator<Item = (K, V)>,
981988
K: fmt::Debug + Hash + Eq,

src/map/slice.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ impl<K, V> Slice<K, V> {
173173

174174
/// Return an iterator over the key-value pairs of the map slice.
175175
pub fn iter(&self) -> Iter<'_, K, V> {
176-
Iter::from_slices((&self.entries, &[]))
176+
Iter::from_slice(&self.entries)
177177
}
178178

179179
/// Return an iterator over the key-value pairs of the map slice.
180180
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> {
181-
IterMut::from_mut_slices((&mut self.entries, &mut []))
181+
IterMut::from_mut_slice(&mut self.entries)
182182
}
183183

184184
/// Return an iterator over the keys of the map slice.
185185
pub fn keys(&self) -> Keys<'_, K, V> {
186-
Keys::from_slices((&self.entries, &[]))
186+
Keys::from_slice(&self.entries)
187187
}
188188

189189
/// Return an owning iterator over the keys of the map slice.
@@ -193,12 +193,12 @@ impl<K, V> Slice<K, V> {
193193

194194
/// Return an iterator over the values of the map slice.
195195
pub fn values(&self) -> Values<'_, K, V> {
196-
Values::from_slices((&self.entries, &[]))
196+
Values::from_slice(&self.entries)
197197
}
198198

199199
/// Return an iterator over mutable references to the the values of the map slice.
200200
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
201-
ValuesMut::from_mut_slices((&mut self.entries, &mut []))
201+
ValuesMut::from_mut_slice(&mut self.entries)
202202
}
203203

204204
/// Return an owning iterator over the values of the map slice.

src/rayon/map.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ pub(super) struct ParBuckets<'a, K, V> {
8383

8484
impl<'a, K, V> ParBuckets<'a, K, V> {
8585
pub(super) fn new(entries: &'a VecDeque<Bucket<K, V>>) -> Self {
86-
Self::from_slices(entries.as_slices())
86+
let (head, tail) = entries.as_slices();
87+
Self { head, tail }
8788
}
8889

89-
pub(super) fn from_slices((head, tail): (&'a [Bucket<K, V>], &'a [Bucket<K, V>])) -> Self {
90-
Self { head, tail }
90+
pub(super) fn from_slice(slice: &'a [Bucket<K, V>]) -> Self {
91+
Self {
92+
head: slice,
93+
tail: &[],
94+
}
9195
}
9296

9397
pub(super) fn iter(&self) -> impl Iterator<Item = &Bucket<K, V>> {
@@ -119,7 +123,7 @@ impl<'a, K: Sync, V: Sync> ParallelIterator for ParBuckets<'a, K, V> {
119123
}
120124
}
121125

122-
impl<'a, K: Sync, V: Sync> IndexedParallelIterator for ParBuckets<'a, K, V> {
126+
impl<K: Sync, V: Sync> IndexedParallelIterator for ParBuckets<'_, K, V> {
123127
fn drive<C>(self, consumer: C) -> C::Result
124128
where
125129
C: Consumer<Self::Item>,
@@ -167,7 +171,7 @@ where
167171

168172
fn into_par_iter(self) -> Self::Iter {
169173
ParIter {
170-
entries: ParBuckets::from_slices((&self.entries, &[])),
174+
entries: ParBuckets::from_slice(&self.entries),
171175
}
172176
}
173177
}
@@ -215,11 +219,15 @@ struct ParBucketsMut<'a, K, V> {
215219

216220
impl<'a, K, V> ParBucketsMut<'a, K, V> {
217221
fn new(entries: &'a mut VecDeque<Bucket<K, V>>) -> Self {
218-
Self::from_mut_slices(entries.as_mut_slices())
222+
let (head, tail) = entries.as_mut_slices();
223+
Self { head, tail }
219224
}
220225

221-
fn from_mut_slices((head, tail): (&'a mut [Bucket<K, V>], &'a mut [Bucket<K, V>])) -> Self {
222-
Self { head, tail }
226+
fn from_mut_slice(slice: &'a mut [Bucket<K, V>]) -> Self {
227+
Self {
228+
head: slice,
229+
tail: &mut [],
230+
}
223231
}
224232

225233
fn iter(&self) -> impl Iterator<Item = &Bucket<K, V>> {
@@ -245,7 +253,7 @@ impl<'a, K: Send, V: Send> ParallelIterator for ParBucketsMut<'a, K, V> {
245253
}
246254
}
247255

248-
impl<'a, K: Send, V: Send> IndexedParallelIterator for ParBucketsMut<'a, K, V> {
256+
impl<K: Send, V: Send> IndexedParallelIterator for ParBucketsMut<'_, K, V> {
249257
fn drive<C>(self, consumer: C) -> C::Result
250258
where
251259
C: Consumer<Self::Item>,
@@ -293,7 +301,7 @@ where
293301

294302
fn into_par_iter(self) -> Self::Iter {
295303
ParIterMut {
296-
entries: ParBucketsMut::from_mut_slices((&mut self.entries, &mut [])),
304+
entries: ParBucketsMut::from_mut_slice(&mut self.entries),
297305
}
298306
}
299307
}
@@ -407,7 +415,7 @@ where
407415
/// in the slice is still preserved for operations like `reduce` and `collect`.
408416
pub fn par_keys(&self) -> ParKeys<'_, K, V> {
409417
ParKeys {
410-
entries: ParBuckets::from_slices((&self.entries, &[])),
418+
entries: ParBuckets::from_slice(&self.entries),
411419
}
412420
}
413421

@@ -417,7 +425,7 @@ where
417425
/// in the slice is still preserved for operations like `reduce` and `collect`.
418426
pub fn par_values(&self) -> ParValues<'_, K, V> {
419427
ParValues {
420-
entries: ParBuckets::from_slices((&self.entries, &[])),
428+
entries: ParBuckets::from_slice(&self.entries),
421429
}
422430
}
423431
}
@@ -530,7 +538,7 @@ where
530538
/// in the slice is still preserved for operations like `reduce` and `collect`.
531539
pub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V> {
532540
ParValuesMut {
533-
entries: ParBucketsMut::from_mut_slices((&mut self.entries, &mut [])),
541+
entries: ParBucketsMut::from_mut_slice(&mut self.entries),
534542
}
535543
}
536544
}

src/rayon/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ where
9898

9999
fn into_par_iter(self) -> Self::Iter {
100100
ParIter {
101-
entries: ParBuckets::from_slices((&self.entries, &[])),
101+
entries: ParBuckets::from_slice(&self.entries),
102102
}
103103
}
104104
}

src/set/iter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ impl<'a, T> Iter<'a, T> {
4040
}
4141
}
4242

43-
pub(super) fn from_slices(slices: (&'a [Bucket<T>], &'a [Bucket<T>])) -> Self {
43+
pub(super) fn from_slice(slice: &'a [Bucket<T>]) -> Self {
4444
Self {
45-
iter: Buckets::from_slices(slices),
45+
iter: Buckets::from_slice(slice),
4646
}
4747
}
4848
}
@@ -607,7 +607,7 @@ impl<I: Iterator> Iterator for UnitValue<I> {
607607
}
608608
}
609609

610-
impl<'a, I, T, S> fmt::Debug for Splice<'a, I, T, S>
610+
impl<I, T, S> fmt::Debug for Splice<'_, I, T, S>
611611
where
612612
I: fmt::Debug + Iterator<Item = T>,
613613
T: fmt::Debug + Hash + Eq,

src/set/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<T> Slice<T> {
109109

110110
/// Return an iterator over the values of the set slice.
111111
pub fn iter(&self) -> Iter<'_, T> {
112-
Iter::from_slices((&self.entries, &[]))
112+
Iter::from_slice(&self.entries)
113113
}
114114

115115
/// Search over a sorted set for a value.

0 commit comments

Comments
 (0)