Skip to content

Commit d36b83c

Browse files
committed
all: Refactor many type bounds
1 parent ab1878a commit d36b83c

37 files changed

+914
-382
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ where
294294
#[cfg(feature = "alloc")]
295295
impl<'a, T: ?Sized + 'a> TryFrom<rust_alloc::borrow::Cow<'a, T>> for Cow<'a, T>
296296
where
297-
T: ToOwned + TryToOwned,
298-
<T as TryToOwned>::Owned: TryFrom<<T as ToOwned>::Owned>,
297+
T: ToOwned + TryToOwned<Owned: TryFrom<<T as ToOwned>::Owned>>,
299298
{
300299
type Error = <<T as TryToOwned>::Owned as TryFrom<<T as ToOwned>::Owned>>::Error;
301300

@@ -307,9 +306,9 @@ where
307306
}
308307
}
309308

310-
impl<B: ?Sized + TryToOwned> Deref for Cow<'_, B>
309+
impl<B> Deref for Cow<'_, B>
311310
where
312-
B::Owned: Borrow<B>,
311+
B: ?Sized + TryToOwned<Owned: Borrow<B>>,
313312
{
314313
type Target = B;
315314

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<K, V> Root<K, V> {
1919
/// a `BTreeMap`, both iterators should produce keys in strictly ascending
2020
/// order, each greater than all keys in the tree, including any keys
2121
/// already in the tree upon entry.
22-
pub(crate) fn try_append_from_sorted_iters<I, A: Allocator>(
22+
pub(crate) fn try_append_from_sorted_iters<I, A>(
2323
&mut self,
2424
left: I,
2525
right: I,
@@ -29,6 +29,7 @@ impl<K, V> Root<K, V> {
2929
where
3030
K: Ord,
3131
I: Iterator<Item = (K, V)> + FusedIterator,
32+
A: Allocator,
3233
{
3334
// We prepare to merge `left` and `right` into a sorted sequence in linear time.
3435
let iter = MergeIter(MergeIterInner::new(left, right));
@@ -40,14 +41,15 @@ impl<K, V> Root<K, V> {
4041
/// Pushes all key-value pairs to the end of the tree, incrementing a
4142
/// `length` variable along the way. The latter makes it easier for the
4243
/// caller to avoid a leak when the iterator panicks.
43-
pub(crate) fn try_bulk_push<I, A: Allocator>(
44+
pub(crate) fn try_bulk_push<I, A>(
4445
&mut self,
4546
iter: I,
4647
length: &mut usize,
4748
alloc: &A,
4849
) -> Result<(), AllocError>
4950
where
5051
I: Iterator<Item = (K, V)>,
52+
A: Allocator,
5153
{
5254
let mut cur_node = self.borrow_mut().last_leaf_edge().into_node();
5355
// Iterate through all key-value pairs, pushing them into nodes at the right level.
@@ -103,9 +105,10 @@ impl<K, V> Root<K, V> {
103105
}
104106

105107
#[cfg(test)]
106-
pub(crate) fn bulk_push<I, A: Allocator>(&mut self, iter: I, length: &mut usize, alloc: &A)
108+
pub(crate) fn bulk_push<I, A>(&mut self, iter: I, length: &mut usize, alloc: &A)
107109
where
108110
I: Iterator<Item = (K, V)>,
111+
A: Allocator,
109112
{
110113
self.try_bulk_push(iter, length, alloc).abort()
111114
}

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

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
88
/// sibling. If successful but at the cost of shrinking the parent node,
99
/// returns that shrunk parent node. Returns an `Err` if the node is
1010
/// an empty root.
11-
fn fix_node_through_parent<A: Allocator>(
11+
fn fix_node_through_parent<A>(
1212
self,
1313
alloc: &A,
14-
) -> Result<Option<NodeRef<marker::Mut<'a>, K, V, marker::Internal>>, Self> {
14+
) -> Result<Option<NodeRef<marker::Mut<'a>, K, V, marker::Internal>>, Self>
15+
where
16+
A: Allocator,
17+
{
1518
let len = self.len();
1619
if len >= MIN_LEN {
1720
Ok(None)
@@ -55,7 +58,10 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
5558
///
5659
/// This method does not expect ancestors to already be underfull upon entry
5760
/// and panics if it encounters an empty ancestor.
58-
pub(crate) fn fix_node_and_affected_ancestors<A: Allocator>(mut self, alloc: &A) -> bool {
61+
pub(crate) fn fix_node_and_affected_ancestors<A>(mut self, alloc: &A) -> bool
62+
where
63+
A: Allocator,
64+
{
5965
loop {
6066
match self.fix_node_through_parent(alloc) {
6167
Ok(Some(parent)) => self = parent.forget_type(),
@@ -68,7 +74,10 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
6874

6975
impl<K, V> Root<K, V> {
7076
/// Removes empty levels on the top, but keeps an empty leaf if the entire tree is empty.
71-
pub(crate) fn fix_top<A: Allocator>(&mut self, alloc: &A) {
77+
pub(crate) fn fix_top<A>(&mut self, alloc: &A)
78+
where
79+
A: Allocator,
80+
{
7281
while self.height() > 0 && self.len() == 0 {
7382
self.pop_internal_level(alloc);
7483
}
@@ -77,7 +86,10 @@ impl<K, V> Root<K, V> {
7786
/// Stocks up or merge away any underfull nodes on the right border of the
7887
/// tree. The other nodes, those that are not the root nor a rightmost edge,
7988
/// must already have at least MIN_LEN elements.
80-
pub(crate) fn fix_right_border<A: Allocator>(&mut self, alloc: &A) {
89+
pub(crate) fn fix_right_border<A>(&mut self, alloc: &A)
90+
where
91+
A: Allocator,
92+
{
8193
self.fix_top(alloc);
8294
if self.len() > 0 {
8395
self.borrow_mut()
@@ -88,7 +100,10 @@ impl<K, V> Root<K, V> {
88100
}
89101

90102
/// The symmetric clone of `fix_right_border`.
91-
pub(crate) fn fix_left_border<A: Allocator>(&mut self, alloc: &A) {
103+
pub(crate) fn fix_left_border<A>(&mut self, alloc: &A)
104+
where
105+
A: Allocator,
106+
{
92107
self.fix_top(alloc);
93108
if self.len() > 0 {
94109
self.borrow_mut()
@@ -120,14 +135,20 @@ impl<K, V> Root<K, V> {
120135
}
121136

122137
impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV> {
123-
fn fix_left_border_of_left_edge<A: Allocator>(mut self, alloc: &A) {
138+
fn fix_left_border_of_left_edge<A>(mut self, alloc: &A)
139+
where
140+
A: Allocator,
141+
{
124142
while let Internal(internal_kv) = self.force() {
125143
self = internal_kv.fix_left_child(alloc).first_kv();
126144
debug_assert!(self.reborrow().into_node().len() > MIN_LEN);
127145
}
128146
}
129147

130-
fn fix_right_border_of_right_edge<A: Allocator>(mut self, alloc: &A) {
148+
fn fix_right_border_of_right_edge<A>(mut self, alloc: &A)
149+
where
150+
A: Allocator,
151+
{
131152
while let Internal(internal_kv) = self.force() {
132153
self = internal_kv.fix_right_child(alloc).last_kv();
133154
debug_assert!(self.reborrow().into_node().len() > MIN_LEN);
@@ -140,10 +161,10 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
140161
/// provisions an extra element to allow merging its children in turn
141162
/// without becoming underfull.
142163
/// Returns the left child.
143-
fn fix_left_child<A: Allocator>(
144-
self,
145-
alloc: &A,
146-
) -> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
164+
fn fix_left_child<A>(self, alloc: &A) -> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>
165+
where
166+
A: Allocator,
167+
{
147168
let mut internal_kv = self.consider_for_balancing();
148169
let left_len = internal_kv.left_child_len();
149170
debug_assert!(internal_kv.right_child_len() >= MIN_LEN);
@@ -163,10 +184,10 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
163184
/// provisions an extra element to allow merging its children in turn
164185
/// without becoming underfull.
165186
/// Returns wherever the right child ended up.
166-
fn fix_right_child<A: Allocator>(
167-
self,
168-
alloc: &A,
169-
) -> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
187+
fn fix_right_child<A>(self, alloc: &A) -> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>
188+
where
189+
A: Allocator,
190+
{
170191
let mut internal_kv = self.consider_for_balancing();
171192
let right_len = internal_kv.right_child_len();
172193
debug_assert!(internal_kv.left_child_len() >= MIN_LEN);

0 commit comments

Comments
 (0)