Skip to content

Commit dcea664

Browse files
authored
Merge pull request #1262 from cuviper/relax-bounds
Relax trait bounds on many structs
2 parents 0baaff5 + 3d63a87 commit dcea664

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+229
-368
lines changed

src/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<T: Send, const N: usize> IntoParallelIterator for [T; N] {
4040

4141
/// Parallel iterator that moves out of an array.
4242
#[derive(Debug, Clone)]
43-
pub struct IntoIter<T: Send, const N: usize> {
43+
pub struct IntoIter<T, const N: usize> {
4444
array: [T; N],
4545
}
4646

src/collections/binary_heap.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use crate::vec;
1212

1313
/// Parallel iterator over a binary heap
1414
#[derive(Debug, Clone)]
15-
pub struct IntoIter<T: Ord + Send> {
15+
pub struct IntoIter<T> {
1616
inner: vec::IntoIter<T>,
1717
}
1818

19-
impl<T: Ord + Send> IntoParallelIterator for BinaryHeap<T> {
19+
impl<T: Send> IntoParallelIterator for BinaryHeap<T> {
2020
type Item = T;
2121
type Iter = IntoIter<T>;
2222

@@ -29,24 +29,24 @@ impl<T: Ord + Send> IntoParallelIterator for BinaryHeap<T> {
2929

3030
delegate_indexed_iterator! {
3131
IntoIter<T> => T,
32-
impl<T: Ord + Send>
32+
impl<T: Send>
3333
}
3434

3535
/// Parallel iterator over an immutable reference to a binary heap
3636
#[derive(Debug)]
37-
pub struct Iter<'a, T: Ord + Sync> {
37+
pub struct Iter<'a, T> {
3838
inner: slice::Iter<'a, T>,
3939
}
4040

41-
impl<'a, T: Ord + Sync> Clone for Iter<'a, T> {
41+
impl<T> Clone for Iter<'_, T> {
4242
fn clone(&self) -> Self {
4343
Iter {
4444
inner: self.inner.clone(),
4545
}
4646
}
4747
}
4848

49-
impl<'a, T: Ord + Sync> IntoParallelIterator for &'a BinaryHeap<T> {
49+
impl<'a, T: Sync> IntoParallelIterator for &'a BinaryHeap<T> {
5050
type Item = &'a T;
5151
type Iter = Iter<'a, T>;
5252

@@ -59,18 +59,20 @@ impl<'a, T: Ord + Sync> IntoParallelIterator for &'a BinaryHeap<T> {
5959

6060
delegate_indexed_iterator! {
6161
Iter<'a, T> => &'a T,
62-
impl<'a, T: Ord + Sync + 'a>
62+
impl<'a, T: Sync + 'a>
6363
}
6464

6565
// `BinaryHeap` doesn't have a mutable `Iterator`
6666

6767
/// Draining parallel iterator that moves out of a binary heap,
6868
/// but keeps the total capacity.
6969
#[derive(Debug)]
70-
pub struct Drain<'a, T: Ord + Send> {
70+
pub struct Drain<'a, T> {
7171
heap: &'a mut BinaryHeap<T>,
7272
}
7373

74+
// NB: The only reason we require `T: Ord` is for `DrainGuard` to reconstruct
75+
// the heap `From<Vec<T>>` afterward, even though that will actually be empty.
7476
impl<'a, T: Ord + Send> ParallelDrainFull for &'a mut BinaryHeap<T> {
7577
type Iter = Drain<'a, T>;
7678
type Item = T;
@@ -80,7 +82,7 @@ impl<'a, T: Ord + Send> ParallelDrainFull for &'a mut BinaryHeap<T> {
8082
}
8183
}
8284

83-
impl<'a, T: Ord + Send> ParallelIterator for Drain<'a, T> {
85+
impl<T: Ord + Send> ParallelIterator for Drain<'_, T> {
8486
type Item = T;
8587

8688
fn drive_unindexed<C>(self, consumer: C) -> C::Result
@@ -95,7 +97,7 @@ impl<'a, T: Ord + Send> ParallelIterator for Drain<'a, T> {
9597
}
9698
}
9799

98-
impl<'a, T: Ord + Send> IndexedParallelIterator for Drain<'a, T> {
100+
impl<T: Ord + Send> IndexedParallelIterator for Drain<'_, T> {
99101
fn drive<C>(self, consumer: C) -> C::Result
100102
where
101103
C: Consumer<Self::Item>,
@@ -117,7 +119,7 @@ impl<'a, T: Ord + Send> IndexedParallelIterator for Drain<'a, T> {
117119
}
118120
}
119121

120-
impl<'a, T: Ord + Send> Drop for Drain<'a, T> {
122+
impl<T> Drop for Drain<'_, T> {
121123
fn drop(&mut self) {
122124
if !self.heap.is_empty() {
123125
// We must not have produced, so just call a normal drain to remove the items.

src/collections/btree_map.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ use crate::vec;
1111

1212
/// Parallel iterator over a B-Tree map
1313
#[derive(Debug)] // std doesn't Clone
14-
pub struct IntoIter<K: Ord + Send, V: Send> {
14+
pub struct IntoIter<K, V> {
1515
inner: vec::IntoIter<(K, V)>,
1616
}
1717

1818
into_par_vec! {
1919
BTreeMap<K, V> => IntoIter<K, V>,
20-
impl<K: Ord + Send, V: Send>
20+
impl<K: Send, V: Send>
2121
}
2222

2323
delegate_iterator! {
2424
IntoIter<K, V> => (K, V),
25-
impl<K: Ord + Send, V: Send>
25+
impl<K: Send, V: Send>
2626
}
2727

2828
/// Parallel iterator over an immutable reference to a B-Tree map
2929
#[derive(Debug)]
30-
pub struct Iter<'a, K: Ord + Sync, V: Sync> {
30+
pub struct Iter<'a, K, V> {
3131
inner: vec::IntoIter<(&'a K, &'a V)>,
3232
}
3333

34-
impl<'a, K: Ord + Sync, V: Sync> Clone for Iter<'a, K, V> {
34+
impl<K, V> Clone for Iter<'_, K, V> {
3535
fn clone(&self) -> Self {
3636
Iter {
3737
inner: self.inner.clone(),
@@ -41,26 +41,26 @@ impl<'a, K: Ord + Sync, V: Sync> Clone for Iter<'a, K, V> {
4141

4242
into_par_vec! {
4343
&'a BTreeMap<K, V> => Iter<'a, K, V>,
44-
impl<'a, K: Ord + Sync, V: Sync>
44+
impl<'a, K: Sync, V: Sync>
4545
}
4646

4747
delegate_iterator! {
4848
Iter<'a, K, V> => (&'a K, &'a V),
49-
impl<'a, K: Ord + Sync + 'a, V: Sync + 'a>
49+
impl<'a, K: Sync + 'a, V: Sync + 'a>
5050
}
5151

5252
/// Parallel iterator over a mutable reference to a B-Tree map
5353
#[derive(Debug)]
54-
pub struct IterMut<'a, K: Ord + Sync, V: Send> {
54+
pub struct IterMut<'a, K, V> {
5555
inner: vec::IntoIter<(&'a K, &'a mut V)>,
5656
}
5757

5858
into_par_vec! {
5959
&'a mut BTreeMap<K, V> => IterMut<'a, K, V>,
60-
impl<'a, K: Ord + Sync, V: Send>
60+
impl<'a, K: Sync, V: Send>
6161
}
6262

6363
delegate_iterator! {
6464
IterMut<'a, K, V> => (&'a K, &'a mut V),
65-
impl<'a, K: Ord + Sync + 'a, V: Send + 'a>
65+
impl<'a, K: Sync + 'a, V: Send + 'a>
6666
}

src/collections/btree_set.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ use crate::vec;
1111

1212
/// Parallel iterator over a B-Tree set
1313
#[derive(Debug)] // std doesn't Clone
14-
pub struct IntoIter<T: Ord + Send> {
14+
pub struct IntoIter<T> {
1515
inner: vec::IntoIter<T>,
1616
}
1717

1818
into_par_vec! {
1919
BTreeSet<T> => IntoIter<T>,
20-
impl<T: Ord + Send>
20+
impl<T: Send>
2121
}
2222

2323
delegate_iterator! {
2424
IntoIter<T> => T,
25-
impl<T: Ord + Send>
25+
impl<T: Send>
2626
}
2727

2828
/// Parallel iterator over an immutable reference to a B-Tree set
2929
#[derive(Debug)]
30-
pub struct Iter<'a, T: Ord + Sync> {
30+
pub struct Iter<'a, T> {
3131
inner: vec::IntoIter<&'a T>,
3232
}
3333

34-
impl<'a, T: Ord + Sync + 'a> Clone for Iter<'a, T> {
34+
impl<T> Clone for Iter<'_, T> {
3535
fn clone(&self) -> Self {
3636
Iter {
3737
inner: self.inner.clone(),
@@ -41,12 +41,12 @@ impl<'a, T: Ord + Sync + 'a> Clone for Iter<'a, T> {
4141

4242
into_par_vec! {
4343
&'a BTreeSet<T> => Iter<'a, T>,
44-
impl<'a, T: Ord + Sync>
44+
impl<'a, T: Sync>
4545
}
4646

4747
delegate_iterator! {
4848
Iter<'a, T> => &'a T,
49-
impl<'a, T: Ord + Sync + 'a>
49+
impl<'a, T: Sync + 'a>
5050
}
5151

5252
// `BTreeSet` doesn't have a mutable `Iterator`

src/collections/hash_map.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! unless you have need to name one of the iterator types.
44
55
use std::collections::HashMap;
6-
use std::hash::{BuildHasher, Hash};
76
use std::marker::PhantomData;
87

98
use crate::iter::plumbing::*;
@@ -13,27 +12,27 @@ use crate::vec;
1312

1413
/// Parallel iterator over a hash map
1514
#[derive(Debug)] // std doesn't Clone
16-
pub struct IntoIter<K: Hash + Eq + Send, V: Send> {
15+
pub struct IntoIter<K, V> {
1716
inner: vec::IntoIter<(K, V)>,
1817
}
1918

2019
into_par_vec! {
2120
HashMap<K, V, S> => IntoIter<K, V>,
22-
impl<K: Hash + Eq + Send, V: Send, S: BuildHasher>
21+
impl<K: Send, V: Send, S>
2322
}
2423

2524
delegate_iterator! {
2625
IntoIter<K, V> => (K, V),
27-
impl<K: Hash + Eq + Send, V: Send>
26+
impl<K: Send, V: Send>
2827
}
2928

3029
/// Parallel iterator over an immutable reference to a hash map
3130
#[derive(Debug)]
32-
pub struct Iter<'a, K: Hash + Eq + Sync, V: Sync> {
31+
pub struct Iter<'a, K, V> {
3332
inner: vec::IntoIter<(&'a K, &'a V)>,
3433
}
3534

36-
impl<'a, K: Hash + Eq + Sync, V: Sync> Clone for Iter<'a, K, V> {
35+
impl<K, V> Clone for Iter<'_, K, V> {
3736
fn clone(&self) -> Self {
3837
Iter {
3938
inner: self.inner.clone(),
@@ -43,41 +42,39 @@ impl<'a, K: Hash + Eq + Sync, V: Sync> Clone for Iter<'a, K, V> {
4342

4443
into_par_vec! {
4544
&'a HashMap<K, V, S> => Iter<'a, K, V>,
46-
impl<'a, K: Hash + Eq + Sync, V: Sync, S: BuildHasher>
45+
impl<'a, K: Sync, V: Sync, S>
4746
}
4847

4948
delegate_iterator! {
5049
Iter<'a, K, V> => (&'a K, &'a V),
51-
impl<'a, K: Hash + Eq + Sync + 'a, V: Sync + 'a>
50+
impl<'a, K: Sync, V: Sync>
5251
}
5352

5453
/// Parallel iterator over a mutable reference to a hash map
5554
#[derive(Debug)]
56-
pub struct IterMut<'a, K: Hash + Eq + Sync, V: Send> {
55+
pub struct IterMut<'a, K, V> {
5756
inner: vec::IntoIter<(&'a K, &'a mut V)>,
5857
}
5958

6059
into_par_vec! {
6160
&'a mut HashMap<K, V, S> => IterMut<'a, K, V>,
62-
impl<'a, K: Hash + Eq + Sync, V: Send, S: BuildHasher>
61+
impl<'a, K: Sync, V: Send, S>
6362
}
6463

6564
delegate_iterator! {
6665
IterMut<'a, K, V> => (&'a K, &'a mut V),
67-
impl<'a, K: Hash + Eq + Sync + 'a, V: Send + 'a>
66+
impl<'a, K: Sync, V: Send>
6867
}
6968

7069
/// Draining parallel iterator that moves out of a hash map,
7170
/// but keeps the total capacity.
7271
#[derive(Debug)]
73-
pub struct Drain<'a, K: Hash + Eq + Send, V: Send> {
72+
pub struct Drain<'a, K, V> {
7473
inner: vec::IntoIter<(K, V)>,
7574
marker: PhantomData<&'a mut HashMap<K, V>>,
7675
}
7776

78-
impl<'a, K: Hash + Eq + Send, V: Send, S: BuildHasher> ParallelDrainFull
79-
for &'a mut HashMap<K, V, S>
80-
{
77+
impl<'a, K: Send, V: Send, S> ParallelDrainFull for &'a mut HashMap<K, V, S> {
8178
type Iter = Drain<'a, K, V>;
8279
type Item = (K, V);
8380

@@ -92,5 +89,5 @@ impl<'a, K: Hash + Eq + Send, V: Send, S: BuildHasher> ParallelDrainFull
9289

9390
delegate_iterator! {
9491
Drain<'_, K, V> => (K, V),
95-
impl<K: Hash + Eq + Send, V: Send>
92+
impl<K: Send, V: Send>
9693
}

src/collections/hash_set.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! unless you have need to name one of the iterator types.
44
55
use std::collections::HashSet;
6-
use std::hash::{BuildHasher, Hash};
76
use std::marker::PhantomData;
87

98
use crate::iter::plumbing::*;
@@ -13,27 +12,27 @@ use crate::vec;
1312

1413
/// Parallel iterator over a hash set
1514
#[derive(Debug)] // std doesn't Clone
16-
pub struct IntoIter<T: Hash + Eq + Send> {
15+
pub struct IntoIter<T> {
1716
inner: vec::IntoIter<T>,
1817
}
1918

2019
into_par_vec! {
2120
HashSet<T, S> => IntoIter<T>,
22-
impl<T: Hash + Eq + Send, S: BuildHasher>
21+
impl<T: Send, S>
2322
}
2423

2524
delegate_iterator! {
2625
IntoIter<T> => T,
27-
impl<T: Hash + Eq + Send>
26+
impl<T: Send>
2827
}
2928

3029
/// Parallel iterator over an immutable reference to a hash set
3130
#[derive(Debug)]
32-
pub struct Iter<'a, T: Hash + Eq + Sync> {
31+
pub struct Iter<'a, T> {
3332
inner: vec::IntoIter<&'a T>,
3433
}
3534

36-
impl<'a, T: Hash + Eq + Sync> Clone for Iter<'a, T> {
35+
impl<T> Clone for Iter<'_, T> {
3736
fn clone(&self) -> Self {
3837
Iter {
3938
inner: self.inner.clone(),
@@ -43,25 +42,25 @@ impl<'a, T: Hash + Eq + Sync> Clone for Iter<'a, T> {
4342

4443
into_par_vec! {
4544
&'a HashSet<T, S> => Iter<'a, T>,
46-
impl<'a, T: Hash + Eq + Sync, S: BuildHasher>
45+
impl<'a, T: Sync, S>
4746
}
4847

4948
delegate_iterator! {
5049
Iter<'a, T> => &'a T,
51-
impl<'a, T: Hash + Eq + Sync + 'a>
50+
impl<'a, T: Sync>
5251
}
5352

5453
// `HashSet` doesn't have a mutable `Iterator`
5554

5655
/// Draining parallel iterator that moves out of a hash set,
5756
/// but keeps the total capacity.
5857
#[derive(Debug)]
59-
pub struct Drain<'a, T: Hash + Eq + Send> {
58+
pub struct Drain<'a, T> {
6059
inner: vec::IntoIter<T>,
6160
marker: PhantomData<&'a mut HashSet<T>>,
6261
}
6362

64-
impl<'a, T: Hash + Eq + Send, S: BuildHasher> ParallelDrainFull for &'a mut HashSet<T, S> {
63+
impl<'a, T: Send, S> ParallelDrainFull for &'a mut HashSet<T, S> {
6564
type Iter = Drain<'a, T>;
6665
type Item = T;
6766

@@ -76,5 +75,5 @@ impl<'a, T: Hash + Eq + Send, S: BuildHasher> ParallelDrainFull for &'a mut Hash
7675

7776
delegate_iterator! {
7877
Drain<'_, T> => T,
79-
impl<T: Hash + Eq + Send>
78+
impl<T: Send>
8079
}

0 commit comments

Comments
 (0)