Skip to content

Commit fad9cf2

Browse files
committed
all: Refactor remaining type bounds
1 parent d36b83c commit fad9cf2

Some content is hidden

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

42 files changed

+2034
-510
lines changed

crates/rune-alloc/src/borrow/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,15 @@ where
396396
}
397397
}
398398

399-
impl<B: ?Sized> Hash for Cow<'_, B>
399+
impl<B> Hash for Cow<'_, B>
400400
where
401-
B: Hash + TryToOwned,
401+
B: ?Sized + Hash + TryToOwned,
402402
{
403403
#[inline]
404-
fn hash<H: Hasher>(&self, state: &mut H) {
404+
fn hash<H>(&self, state: &mut H)
405+
where
406+
H: Hasher,
407+
{
405408
Hash::hash(&**self, state)
406409
}
407410
}

crates/rune-alloc/src/boxed.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,10 @@ where
11591159
A: Allocator,
11601160
{
11611161
#[inline]
1162-
fn hash<H: Hasher>(&self, state: &mut H) {
1162+
fn hash<H>(&self, state: &mut H)
1163+
where
1164+
H: Hasher,
1165+
{
11631166
(**self).hash(state);
11641167
}
11651168
}

crates/rune-alloc/src/btree/append.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,14 @@ impl<K, V> Root<K, V> {
115115
}
116116

117117
// An iterator for merging two sorted sequences into one
118-
struct MergeIter<K, V, I: Iterator<Item = (K, V)>>(MergeIterInner<I>);
118+
struct MergeIter<K, V, I>(MergeIterInner<I>)
119+
where
120+
I: Iterator<Item = (K, V)>;
119121

120-
impl<K: Ord, V, I> Iterator for MergeIter<K, V, I>
122+
impl<K, V, I> Iterator for MergeIter<K, V, I>
121123
where
122124
I: Iterator<Item = (K, V)> + FusedIterator,
125+
K: Ord,
123126
{
124127
type Item = (K, V);
125128

crates/rune-alloc/src/btree/fix.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ use crate::alloc::Allocator;
33
use super::map::MIN_LEN;
44
use super::node::{marker, ForceResult::*, Handle, LeftOrRight::*, NodeRef, Root};
55

6-
impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
6+
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>
7+
where
8+
K: 'a,
9+
V: 'a,
10+
{
711
/// Stocks up a possibly underfull node by merging with or stealing from a
812
/// sibling. If successful but at the cost of shrinking the parent node,
913
/// returns that shrunk parent node. Returns an `Err` if the node is
@@ -50,7 +54,11 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
5054
}
5155
}
5256

53-
impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
57+
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>
58+
where
59+
K: 'a,
60+
V: 'a,
61+
{
5462
/// Stocks up a possibly underfull node, and if that causes its parent node
5563
/// to shrink, stocks up the parent, recursively.
5664
/// Returns `true` if it fixed the tree, `false` if it couldn't because the
@@ -134,7 +142,11 @@ impl<K, V> Root<K, V> {
134142
}
135143
}
136144

137-
impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV> {
145+
impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV>
146+
where
147+
K: 'a,
148+
V: 'a,
149+
{
138150
fn fix_left_border_of_left_edge<A>(mut self, alloc: &A)
139151
where
140152
A: Allocator,
@@ -156,7 +168,11 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
156168
}
157169
}
158170

159-
impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::KV> {
171+
impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::KV>
172+
where
173+
K: 'a,
174+
V: 'a,
175+
{
160176
/// Stocks up the left child, assuming the right child isn't underfull, and
161177
/// provisions an extra element to allow merging its children in turn
162178
/// without becoming underfull.

crates/rune-alloc/src/btree/map.rs

Lines changed: 100 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ where
261261
{
262262
}
263263

264-
impl<K: TryClone, V: TryClone, A: Allocator + Clone> TryClone for BTreeMap<K, V, A> {
264+
impl<K, V, A> TryClone for BTreeMap<K, V, A>
265+
where
266+
K: TryClone,
267+
V: TryClone,
268+
A: Allocator + Clone,
269+
{
265270
fn try_clone(&self) -> Result<BTreeMap<K, V, A>, Error> {
266271
fn clone_subtree<'a, K, V, A>(
267272
node: NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>,
@@ -524,18 +529,31 @@ impl<K, V> Clone for IterRaw<K, V> {
524529
///
525530
/// [`iter`]: BTreeMap::iter
526531
#[must_use = "iterators are lazy and do nothing unless consumed"]
527-
pub struct Iter<'a, K: 'a, V: 'a> {
532+
pub struct Iter<'a, K, V>
533+
where
534+
K: 'a,
535+
V: 'a,
536+
{
528537
range: LazyLeafRange<marker::Immut<'a>, K, V>,
529538
length: usize,
530539
}
531540

532-
impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Iter<'_, K, V> {
541+
impl<K, V> fmt::Debug for Iter<'_, K, V>
542+
where
543+
K: fmt::Debug,
544+
V: fmt::Debug,
545+
{
546+
#[inline]
533547
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
534548
f.debug_list().entries(self.clone()).finish()
535549
}
536550
}
537551

538-
impl<'a, K: 'a, V: 'a> Default for Iter<'a, K, V> {
552+
impl<'a, K, V> Default for Iter<'a, K, V>
553+
where
554+
K: 'a,
555+
V: 'a,
556+
{
539557
/// Creates an empty `btree_map::Iter`.
540558
///
541559
/// ```
@@ -544,6 +562,7 @@ impl<'a, K: 'a, V: 'a> Default for Iter<'a, K, V> {
544562
/// let iter: btree_map::Iter<'_, u8, u8> = Default::default();
545563
/// assert_eq!(iter.len(), 0);
546564
/// ```
565+
#[inline]
547566
fn default() -> Self {
548567
Iter {
549568
range: Default::default(),
@@ -558,7 +577,11 @@ impl<'a, K: 'a, V: 'a> Default for Iter<'a, K, V> {
558577
/// documentation for more.
559578
///
560579
/// [`iter_mut`]: BTreeMap::iter_mut
561-
pub struct IterMut<'a, K: 'a, V: 'a> {
580+
pub struct IterMut<'a, K, V>
581+
where
582+
K: 'a,
583+
V: 'a,
584+
{
562585
range: LazyLeafRange<marker::ValMut<'a>, K, V>,
563586
length: usize,
564587

@@ -576,7 +599,11 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IterMut<'_, K, V> {
576599
}
577600
}
578601

579-
impl<'a, K: 'a, V: 'a> Default for IterMut<'a, K, V> {
602+
impl<'a, K, V> Default for IterMut<'a, K, V>
603+
where
604+
K: 'a,
605+
V: 'a,
606+
{
580607
/// Creates an empty `btree_map::IterMut`.
581608
///
582609
/// ```
@@ -762,7 +789,11 @@ where
762789
///
763790
/// [`range`]: BTreeMap::range
764791
#[must_use = "iterators are lazy and do nothing unless consumed"]
765-
pub struct Range<'a, K: 'a, V: 'a> {
792+
pub struct Range<'a, K, V>
793+
where
794+
K: 'a,
795+
V: 'a,
796+
{
766797
inner: LeafRange<marker::Immut<'a>, K, V>,
767798
}
768799

@@ -779,7 +810,11 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Range<'_, K, V> {
779810
///
780811
/// [`range_mut`]: BTreeMap::range_mut
781812
#[must_use = "iterators are lazy and do nothing unless consumed"]
782-
pub struct RangeMut<'a, K: 'a, V: 'a> {
813+
pub struct RangeMut<'a, K, V>
814+
where
815+
K: 'a,
816+
V: 'a,
817+
{
783818
inner: LeafRange<marker::ValMut<'a>, K, V>,
784819

785820
// Be invariant in `K` and `V`
@@ -1900,7 +1935,11 @@ where
19001935
}
19011936
}
19021937

1903-
impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
1938+
impl<'a, K, V> Iterator for Iter<'a, K, V>
1939+
where
1940+
K: 'a,
1941+
V: 'a,
1942+
{
19041943
type Item = (&'a K, &'a V);
19051944

19061945
#[inline]
@@ -1942,7 +1981,11 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
19421981

19431982
impl<K, V> FusedIterator for Iter<'_, K, V> {}
19441983

1945-
impl<'a, K: 'a, V: 'a> DoubleEndedIterator for Iter<'a, K, V> {
1984+
impl<'a, K, V> DoubleEndedIterator for Iter<'a, K, V>
1985+
where
1986+
K: 'a,
1987+
V: 'a,
1988+
{
19461989
#[inline]
19471990
fn next_back(&mut self) -> Option<(&'a K, &'a V)> {
19481991
if self.length == 0 {
@@ -2676,7 +2719,11 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> {
26762719

26772720
impl<K, V> FusedIterator for RangeMut<'_, K, V> {}
26782721

2679-
impl<K: Ord, V, A: Allocator + Clone> TryExtend<(K, V)> for BTreeMap<K, V, A> {
2722+
impl<K, V, A> TryExtend<(K, V)> for BTreeMap<K, V, A>
2723+
where
2724+
K: Ord,
2725+
A: Allocator + Clone,
2726+
{
26802727
#[inline]
26812728
fn try_extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) -> Result<(), Error> {
26822729
for (k, v) in iter {
@@ -2688,15 +2735,22 @@ impl<K: Ord, V, A: Allocator + Clone> TryExtend<(K, V)> for BTreeMap<K, V, A> {
26882735
}
26892736

26902737
#[cfg(test)]
2691-
impl<K: Ord, V, A: Allocator + Clone> Extend<(K, V)> for BTreeMap<K, V, A> {
2738+
impl<K, V, A> Extend<(K, V)> for BTreeMap<K, V, A>
2739+
where
2740+
K: Ord,
2741+
A: Allocator + Clone,
2742+
{
26922743
#[inline]
26932744
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) {
26942745
self.try_extend(iter).abort();
26952746
}
26962747
}
26972748

2698-
impl<'a, K: Ord + Copy, V: Copy, A: Allocator + Clone> TryExtend<(&'a K, &'a V)>
2699-
for BTreeMap<K, V, A>
2749+
impl<'a, K, V, A> TryExtend<(&'a K, &'a V)> for BTreeMap<K, V, A>
2750+
where
2751+
K: Ord + Copy,
2752+
V: Copy,
2753+
A: Allocator + Clone,
27002754
{
27012755
#[inline]
27022756
fn try_extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I) -> Result<(), Error> {
@@ -2705,8 +2759,11 @@ impl<'a, K: Ord + Copy, V: Copy, A: Allocator + Clone> TryExtend<(&'a K, &'a V)>
27052759
}
27062760

27072761
#[cfg(test)]
2708-
impl<'a, K: Ord + Copy, V: Copy, A: Allocator + Clone> Extend<(&'a K, &'a V)>
2709-
for BTreeMap<K, V, A>
2762+
impl<'a, K, V, A> Extend<(&'a K, &'a V)> for BTreeMap<K, V, A>
2763+
where
2764+
K: Ord + Copy,
2765+
V: Copy,
2766+
A: Allocator + Clone,
27102767
{
27112768
#[inline]
27122769
fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I) {
@@ -2721,7 +2778,10 @@ where
27212778
A: Allocator,
27222779
{
27232780
#[inline]
2724-
fn hash<H: Hasher>(&self, state: &mut H) {
2781+
fn hash<H>(&self, state: &mut H)
2782+
where
2783+
H: Hasher,
2784+
{
27252785
state.write_usize(self.len());
27262786

27272787
for elt in self {
@@ -3288,19 +3348,29 @@ where
32883348
/// first elements of the tree.
32893349
///
32903350
/// A `Cursor` is created with the [`BTreeMap::lower_bound`] and [`BTreeMap::upper_bound`] methods.
3291-
pub struct Cursor<'a, K: 'a, V: 'a> {
3351+
pub struct Cursor<'a, K, V>
3352+
where
3353+
K: 'a,
3354+
V: 'a,
3355+
{
32923356
current: Option<Handle<NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>, marker::KV>>,
32933357
root: Option<&'a node::Root<K, V>>,
32943358
}
32953359

32963360
impl<K, V> Clone for Cursor<'_, K, V> {
3361+
#[inline]
32973362
fn clone(&self) -> Self {
32983363
let Cursor { current, root } = *self;
32993364
Cursor { current, root }
33003365
}
33013366
}
33023367

3303-
impl<K: Debug, V: Debug> Debug for Cursor<'_, K, V> {
3368+
impl<K, V> Debug for Cursor<'_, K, V>
3369+
where
3370+
K: Debug,
3371+
V: Debug,
3372+
{
3373+
#[inline]
33043374
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33053375
f.debug_tuple("Cursor").field(&self.key_value()).finish()
33063376
}
@@ -3319,7 +3389,11 @@ impl<K: Debug, V: Debug> Debug for Cursor<'_, K, V> {
33193389
///
33203390
/// A `Cursor` is created with the [`BTreeMap::lower_bound_mut`] and [`BTreeMap::upper_bound_mut`]
33213391
/// methods.
3322-
pub struct CursorMut<'a, K: 'a, V: 'a, A = Global> {
3392+
pub struct CursorMut<'a, K, V, A = Global>
3393+
where
3394+
K: 'a,
3395+
V: 'a,
3396+
{
33233397
current: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV>>,
33243398
#[cfg_attr(not(test), allow(unused))]
33253399
root: DormantMutRef<'a, Option<node::Root<K, V>>>,
@@ -3329,7 +3403,12 @@ pub struct CursorMut<'a, K: 'a, V: 'a, A = Global> {
33293403
alloc: &'a mut A,
33303404
}
33313405

3332-
impl<K: Debug, V: Debug, A> Debug for CursorMut<'_, K, V, A> {
3406+
impl<K, V, A> Debug for CursorMut<'_, K, V, A>
3407+
where
3408+
K: Debug,
3409+
V: Debug,
3410+
{
3411+
#[inline]
33333412
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33343413
f.debug_tuple("CursorMut").field(&self.key_value()).finish()
33353414
}

0 commit comments

Comments
 (0)