From 878152d70108a743b8122362f743bcb3d87f7381 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Fri, 3 May 2024 18:05:12 +0200 Subject: [PATCH] Fix new Clippy lint multiple_bound_locations --- crates/rune-alloc/src/btree/map.rs | 76 ++++++++------- crates/rune-alloc/src/btree/set.rs | 26 ++--- crates/rune-alloc/src/hashbrown/map.rs | 110 +++++++++++----------- crates/rune-alloc/src/hashbrown/set.rs | 24 ++--- crates/rune-alloc/src/iter/ext.rs | 4 +- crates/rune/src/compile/context.rs | 4 +- crates/rune/src/compile/names.rs | 4 +- crates/rune/src/module/function_traits.rs | 8 +- crates/rune/src/query/query.rs | 4 +- crates/rune/src/runtime/bytes.rs | 2 +- crates/rune/src/runtime/object.rs | 20 ++-- crates/rune/src/runtime/value.rs | 8 +- crates/rune/src/runtime/vec.rs | 2 +- 13 files changed, 152 insertions(+), 140 deletions(-) diff --git a/crates/rune-alloc/src/btree/map.rs b/crates/rune-alloc/src/btree/map.rs index a75dab426..887319193 100644 --- a/crates/rune-alloc/src/btree/map.rs +++ b/crates/rune-alloc/src/btree/map.rs @@ -65,9 +65,9 @@ pub(crate) fn into_ok(result: Result) -> T { } #[inline(always)] -pub(crate) fn infallible_cmp(_: &mut (), a: &T, b: &T) -> Result +pub(crate) fn infallible_cmp(_: &mut (), a: &T, b: &T) -> Result where - T: Ord, + T: ?Sized + Ord, { Ok(a.cmp(b)) } @@ -253,13 +253,14 @@ where impl TryClone for BTreeMap { fn try_clone(&self) -> Result, Error> { - fn clone_subtree<'a, K: TryClone, V: TryClone, A: Allocator + Clone>( + fn clone_subtree<'a, K, V, A>( node: NodeRef, K, V, marker::LeafOrInternal>, alloc: &A, ) -> Result, Error> where - K: 'a, - V: 'a, + K: 'a + TryClone, + V: 'a + TryClone, + A: Allocator + Clone, { match node.force() { Leaf(leaf) => { @@ -862,21 +863,23 @@ impl BTreeMap { /// assert_eq!(map.get(&2), None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn get(&self, key: &Q) -> Option<&V> + pub fn get(&self, key: &Q) -> Option<&V> where + Q: ?Sized + Ord, K: Borrow + Ord, - Q: Ord, { into_ok(self.get_with(&mut (), key, infallible_cmp)) } - pub(crate) fn get_with( + pub(crate) fn get_with( &self, cx: &mut C, key: &Q, cmp: CmpFn, ) -> Result, E> where + C: ?Sized, + Q: ?Sized, K: Borrow, { let Some(root_node) = self.root.as_ref().map(NodeRef::reborrow) else { @@ -905,10 +908,10 @@ impl BTreeMap { /// assert_eq!(map.get_key_value(&2), None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> + pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> where + Q: ?Sized + Ord, K: Borrow + Ord, - Q: Ord, { let root_node = self.root.as_ref()?.reborrow(); match into_ok(root_node.search_tree(&mut (), k, infallible_cmp)) { @@ -1103,23 +1106,24 @@ impl BTreeMap { /// assert_eq!(map.contains_key(&2), false); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn contains_key(&self, key: &Q) -> bool + pub fn contains_key(&self, key: &Q) -> bool where + Q: ?Sized + Ord, K: Borrow + Ord, - Q: Ord, { into_ok(self.contains_key_with(&mut (), key, infallible_cmp)) } - pub(crate) fn contains_key_with( + pub(crate) fn contains_key_with( &self, cx: &mut C, key: &Q, cmp: CmpFn, ) -> Result where + C: ?Sized, + Q: ?Sized + Ord, K: Borrow + Ord, - Q: Ord, { Ok(self.get_with(cx, key, cmp)?.is_some()) } @@ -1148,10 +1152,10 @@ impl BTreeMap { /// # Ok::<_, rune::alloc::Error>(()) /// ``` // See `get` for implementation notes, this is basically a copy-paste with mut's added - pub fn get_mut(&mut self, key: &Q) -> Option<&mut V> + pub fn get_mut(&mut self, key: &Q) -> Option<&mut V> where + Q: ?Sized + Ord, K: Borrow + Ord, - Q: Ord, { into_ok(self.get_mut_with(&mut (), key, infallible_cmp)) } @@ -1296,10 +1300,10 @@ impl BTreeMap { /// assert_eq!(map.remove(&1), None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn remove(&mut self, key: &Q) -> Option + pub fn remove(&mut self, key: &Q) -> Option where + Q: ?Sized + Ord, K: Borrow + Ord, - Q: Ord, { self.remove_entry(key).map(|(_, v)| v) } @@ -1323,9 +1327,9 @@ impl BTreeMap { /// assert_eq!(map.remove_entry(&1), None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn remove_entry(&mut self, key: &Q) -> Option<(K, V)> + pub fn remove_entry(&mut self, key: &Q) -> Option<(K, V)> where - Q: Ord, + Q: ?Sized + Ord, K: Borrow + Ord, { into_ok(self.remove_entry_with(&mut (), key, infallible_cmp)) @@ -1485,22 +1489,24 @@ impl BTreeMap { /// assert_eq!(Some((&5, &"b")), map.range(4..).next()); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn range(&self, range: R) -> Range<'_, K, V> + pub fn range(&self, range: R) -> Range<'_, K, V> where - Q: Ord, + Q: ?Sized + Ord, K: Borrow + Ord, R: RangeBounds, { into_ok(self.range_with(&mut (), range, infallible_cmp)) } - pub(crate) fn range_with( + pub(crate) fn range_with( &self, cx: &mut C, range: R, cmp: CmpFn, ) -> Result, E> where + C: ?Sized, + Q: ?Sized, K: Borrow, R: RangeBounds, { @@ -1546,9 +1552,9 @@ impl BTreeMap { /// } /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn range_mut(&mut self, range: R) -> RangeMut<'_, K, V> + pub fn range_mut(&mut self, range: R) -> RangeMut<'_, K, V> where - Q: Ord, + Q: ?Sized + Ord, K: Borrow + Ord, R: RangeBounds, { @@ -1672,9 +1678,9 @@ impl BTreeMap { /// assert_eq!(b[&41], "e"); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn try_split_off(&mut self, key: &Q) -> Result + pub fn try_split_off(&mut self, key: &Q) -> Result where - Q: Ord, + Q: ?Sized + Ord, K: Borrow + Ord, A: Clone, { @@ -1682,9 +1688,9 @@ impl BTreeMap { } #[cfg(test)] - pub(crate) fn split_off(&mut self, key: &Q) -> Self + pub(crate) fn split_off(&mut self, key: &Q) -> Self where - Q: Ord, + Q: ?Sized + Ord, K: Borrow + Ord, A: Clone, { @@ -2945,21 +2951,23 @@ impl BTreeMap { /// assert_eq!(cursor.key(), Some(&3)); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn lower_bound_mut(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A> + pub fn lower_bound_mut(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A> where + Q: ?Sized + Ord, K: Borrow + Ord, - Q: Ord, { into_ok(self.lower_bound_mut_with(&mut (), bound, infallible_cmp)) } - pub(crate) fn lower_bound_mut_with( + pub(crate) fn lower_bound_mut_with( &mut self, cx: &mut C, bound: Bound<&Q>, cmp: CmpFn, ) -> Result, E> where + C: ?Sized, + Q: ?Sized, K: Borrow, { let (root, dormant_root) = DormantMutRef::new(&mut self.root); @@ -3067,10 +3075,10 @@ impl BTreeMap { /// assert_eq!(cursor.key(), Some(&2)); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn upper_bound_mut(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A> + pub fn upper_bound_mut(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A> where + Q: ?Sized + Ord, K: Borrow, - Q: Ord, { into_ok(self.upper_bound_mut_with(&mut (), bound, infallible_cmp)) } diff --git a/crates/rune-alloc/src/btree/set.rs b/crates/rune-alloc/src/btree/set.rs index 0ff0947cc..0c9a52abd 100644 --- a/crates/rune-alloc/src/btree/set.rs +++ b/crates/rune-alloc/src/btree/set.rs @@ -413,9 +413,9 @@ impl BTreeSet { /// assert_eq!(Some(&5), set.range(4..).next()); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn range(&self, range: R) -> Range<'_, T> + pub fn range(&self, range: R) -> Range<'_, T> where - K: Ord, + K: ?Sized + Ord, T: Borrow + Ord, R: RangeBounds, { @@ -653,10 +653,10 @@ impl BTreeSet { /// assert_eq!(set.contains(&4), false); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn contains(&self, value: &Q) -> bool + pub fn contains(&self, value: &Q) -> bool where T: Borrow + Ord, - Q: Ord, + Q: ?Sized + Ord, { self.map.contains_key(value) } @@ -678,10 +678,10 @@ impl BTreeSet { /// assert_eq!(set.get(&4), None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn get(&self, value: &Q) -> Option<&T> + pub fn get(&self, value: &Q) -> Option<&T> where T: Borrow + Ord, - Q: Ord, + Q: ?Sized + Ord, { into_ok(self.get_with(&mut (), value, infallible_cmp)) } @@ -1033,10 +1033,10 @@ impl BTreeSet { /// assert_eq!(set.remove(&2), false); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn remove(&mut self, value: &Q) -> bool + pub fn remove(&mut self, value: &Q) -> bool where T: Borrow + Ord, - Q: Ord, + Q: ?Sized + Ord, { self.map.remove(value).is_some() } @@ -1058,10 +1058,10 @@ impl BTreeSet { /// assert_eq!(set.take(&2), None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn take(&mut self, value: &Q) -> Option + pub fn take(&mut self, value: &Q) -> Option where T: Borrow + Ord, - Q: Ord, + Q: ?Sized + Ord, { into_ok(self.take_with(&mut (), value, infallible_cmp)) } @@ -1176,8 +1176,9 @@ impl BTreeSet { /// assert!(b.contains(&41)); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn try_split_off(&mut self, value: &Q) -> Result + pub fn try_split_off(&mut self, value: &Q) -> Result where + Q: ?Sized + Ord, T: Borrow + Ord, A: Clone, { @@ -1187,8 +1188,9 @@ impl BTreeSet { } #[cfg(test)] - pub(crate) fn split_off(&mut self, value: &Q) -> Self + pub(crate) fn split_off(&mut self, value: &Q) -> Self where + Q: ?Sized + Ord, T: Borrow + Ord, A: Clone, { diff --git a/crates/rune-alloc/src/hashbrown/map.rs b/crates/rune-alloc/src/hashbrown/map.rs index d59663ee4..b1222b6f5 100644 --- a/crates/rune-alloc/src/hashbrown/map.rs +++ b/crates/rune-alloc/src/hashbrown/map.rs @@ -206,10 +206,12 @@ pub struct HashMap { pub(crate) table: RawTable<(K, V), A>, } -impl TryClone for HashMap +impl TryClone for HashMap where K: TryClone, V: TryClone, + S: Clone, + A: Allocator + Clone, { fn try_clone(&self) -> Result { Ok(HashMap { @@ -228,10 +230,12 @@ where } #[cfg(test)] -impl Clone for HashMap +impl Clone for HashMap where K: TryClone, V: TryClone, + S: Clone, + A: Allocator + Clone, { fn clone(&self) -> Self { self.try_clone().abort() @@ -245,9 +249,9 @@ where /// Ensures that a single closure type across uses of this which, in turn prevents multiple /// instances of any functions like RawTable::reserve from being generated #[cfg_attr(feature = "inline-more", inline)] -pub(crate) fn make_hasher(hash_builder: &S) -> impl HasherFn<(), T, Infallible> + '_ +pub(crate) fn make_hasher(hash_builder: &S) -> impl HasherFn<(), T, Infallible> + '_ where - T: Hash, + T: ?Sized + Hash, S: BuildHasher, { move |_: &mut (), value: &T| Ok(make_hash::(hash_builder, value)) @@ -275,9 +279,9 @@ where #[cfg(not(rune_nightly))] #[cfg_attr(feature = "inline-more", inline)] -pub(crate) fn make_hash(hash_builder: &S, val: &Q) -> u64 +pub(crate) fn make_hash(hash_builder: &S, val: &Q) -> u64 where - Q: Hash, + Q: ?Sized + Hash, S: BuildHasher, { hash_builder.hash_one(val) @@ -1326,9 +1330,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn entry_ref<'a, 'b, Q: ?Sized>(&'a mut self, key: &'b Q) -> EntryRef<'a, 'b, K, Q, V, S, A> + pub fn entry_ref<'a, 'b, Q>(&'a mut self, key: &'b Q) -> EntryRef<'a, 'b, K, Q, V, S, A> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { let hash = make_hash::(&self.hash_builder, key); @@ -1369,9 +1373,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[inline] - pub fn get(&self, k: &Q) -> Option<&V> + pub fn get(&self, k: &Q) -> Option<&V> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner(k) { @@ -1401,9 +1405,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[inline] - pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> + pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner(k) { @@ -1413,9 +1417,9 @@ where } #[inline] - fn get_inner(&self, k: &Q) -> Option<&(K, V)> + fn get_inner(&self, k: &Q) -> Option<&(K, V)> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { if self.table.is_empty() { None @@ -1450,9 +1454,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[inline] - pub fn get_key_value_mut(&mut self, k: &Q) -> Option<(&K, &mut V)> + pub fn get_key_value_mut(&mut self, k: &Q) -> Option<(&K, &mut V)> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner_mut(k) { @@ -1482,9 +1486,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn contains_key(&self, k: &Q) -> bool + pub fn contains_key(&self, k: &Q) -> bool where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { self.get_inner(k).is_some() } @@ -1514,9 +1518,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> + pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.get_inner_mut(k) { @@ -1526,9 +1530,9 @@ where } #[inline] - fn get_inner_mut(&mut self, k: &Q) -> Option<&mut (K, V)> + fn get_inner_mut(&mut self, k: &Q) -> Option<&mut (K, V)> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { if self.table.is_empty() { None @@ -1582,9 +1586,9 @@ where /// assert_eq!(got, None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn get_many_mut(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]> + pub fn get_many_mut(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { self.get_many_mut_inner(ks).map(|res| res.map(|(_, v)| v)) } @@ -1635,12 +1639,12 @@ where /// assert_eq!(got, None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub unsafe fn get_many_unchecked_mut( + pub unsafe fn get_many_unchecked_mut( &mut self, ks: [&Q; N], ) -> Option<[&'_ mut V; N]> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { self.get_many_unchecked_mut_inner(ks) .map(|res| res.map(|(_, v)| v)) @@ -1691,12 +1695,12 @@ where /// assert_eq!(got, None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub fn get_many_key_value_mut( + pub fn get_many_key_value_mut( &mut self, ks: [&Q; N], ) -> Option<[(&'_ K, &'_ mut V); N]> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { self.get_many_mut_inner(ks) .map(|res| res.map(|(k, v)| (&*k, v))) @@ -1747,23 +1751,20 @@ where /// assert_eq!(got, None); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - pub unsafe fn get_many_key_value_unchecked_mut( + pub unsafe fn get_many_key_value_unchecked_mut( &mut self, ks: [&Q; N], ) -> Option<[(&'_ K, &'_ mut V); N]> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { self.get_many_unchecked_mut_inner(ks) .map(|res| res.map(|(k, v)| (&*k, v))) } - fn get_many_mut_inner( - &mut self, - ks: [&Q; N], - ) -> Option<[&'_ mut (K, V); N]> + fn get_many_mut_inner(&mut self, ks: [&Q; N]) -> Option<[&'_ mut (K, V); N]> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { let hashes = self.build_hashes_inner(ks); into_ok( @@ -1772,12 +1773,12 @@ where ) } - unsafe fn get_many_unchecked_mut_inner( + unsafe fn get_many_unchecked_mut_inner( &mut self, ks: [&Q; N], ) -> Option<[&'_ mut (K, V); N]> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { let hashes = self.build_hashes_inner(ks); into_ok( @@ -1786,9 +1787,9 @@ where ) } - fn build_hashes_inner(&self, ks: [&Q; N]) -> [u64; N] + fn build_hashes_inner(&self, ks: [&Q; N]) -> [u64; N] where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { let mut hashes = [0_u64; N]; for i in 0..N { @@ -1994,9 +1995,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn remove(&mut self, k: &Q) -> Option + pub fn remove(&mut self, k: &Q) -> Option where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.remove_entry(k) { @@ -2034,9 +2035,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn remove_entry(&mut self, k: &Q) -> Option<(K, V)> + pub fn remove_entry(&mut self, k: &Q) -> Option<(K, V)> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { let hash = make_hash::(&self.hash_builder, k); into_ok(self.table.remove_entry(&mut (), hash, equivalent_key(k))) @@ -2338,10 +2339,10 @@ where } } -impl Index<&Q> for HashMap +impl Index<&Q> for HashMap where K: Eq + Hash, - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, S: BuildHasher, A: Allocator, { @@ -3307,10 +3308,10 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] - pub fn from_key(self, k: &Q) -> RawEntryMut<'a, K, V, S, A> + pub fn from_key(self, k: &Q) -> RawEntryMut<'a, K, V, S, A> where S: BuildHasher, - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { let hash = make_hash::(&self.map.hash_builder, k); self.from_key_hashed_nocheck(hash, k) @@ -3341,9 +3342,9 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilderMut<'a, K, V, S, A> { /// ``` #[inline] #[allow(clippy::wrong_self_convention)] - pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S, A> + pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S, A> where - Q: Equivalent, + Q: ?Sized + Equivalent, { self.from_hash(hash, equivalent(k)) } @@ -3420,10 +3421,10 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilder<'a, K, V, S, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] - pub fn from_key(self, k: &Q) -> Option<(&'a K, &'a V)> + pub fn from_key(self, k: &Q) -> Option<(&'a K, &'a V)> where S: BuildHasher, - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { let hash = make_hash::(&self.map.hash_builder, k); self.from_key_hashed_nocheck(hash, k) @@ -3452,9 +3453,9 @@ impl<'a, K, V, S, A: Allocator> RawEntryBuilder<'a, K, V, S, A> { /// ``` #[cfg_attr(feature = "inline-more", inline)] #[allow(clippy::wrong_self_convention)] - pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)> + pub fn from_key_hashed_nocheck(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)> where - Q: Equivalent, + Q: ?Sized + Equivalent, { self.from_hash(hash, equivalent(k)) } @@ -4630,8 +4631,9 @@ impl Debug for VacantEntry<'_, K, V, S, A> { /// assert_eq!(map.len(), 6); /// # Ok::<_, rune::alloc::Error>(()) /// ``` -pub enum EntryRef<'a, 'b, K, Q: ?Sized, V, S, A = Global> +pub enum EntryRef<'a, 'b, K, Q, V, S, A = Global> where + Q: ?Sized, A: Allocator, { /// An occupied entry. diff --git a/crates/rune-alloc/src/hashbrown/set.rs b/crates/rune-alloc/src/hashbrown/set.rs index 220b0a0a4..9fb0543ef 100644 --- a/crates/rune-alloc/src/hashbrown/set.rs +++ b/crates/rune-alloc/src/hashbrown/set.rs @@ -923,9 +923,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn contains(&self, value: &Q) -> bool + pub fn contains(&self, value: &Q) -> bool where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { self.map.contains_key(value) } @@ -950,9 +950,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn get(&self, value: &Q) -> Option<&T> + pub fn get(&self, value: &Q) -> Option<&T> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.map.get_key_value(value) { @@ -1009,9 +1009,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[inline] - pub fn get_or_try_insert_owned(&mut self, value: &Q) -> Result<&T, Error> + pub fn get_or_try_insert_owned(&mut self, value: &Q) -> Result<&T, Error> where - Q: Hash + Equivalent + TryToOwned, + Q: ?Sized + Hash + Equivalent + TryToOwned, { // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with // `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`. @@ -1044,9 +1044,9 @@ where /// # Ok::<_, rune::alloc::Error>(()) /// ``` #[cfg_attr(feature = "inline-more", inline)] - pub fn get_or_try_insert_with(&mut self, value: &Q, f: F) -> Result<&T, Error> + pub fn get_or_try_insert_with(&mut self, value: &Q, f: F) -> Result<&T, Error> where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, F: FnOnce(&Q) -> Result, { // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with @@ -1278,9 +1278,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn remove(&mut self, value: &Q) -> bool + pub fn remove(&mut self, value: &Q) -> bool where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { self.map.remove(value).is_some() } @@ -1305,9 +1305,9 @@ where /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html /// [`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html #[cfg_attr(feature = "inline-more", inline)] - pub fn take(&mut self, value: &Q) -> Option + pub fn take(&mut self, value: &Q) -> Option where - Q: Hash + Equivalent, + Q: ?Sized + Hash + Equivalent, { // Avoid `Option::map` because it bloats LLVM IR. match self.map.remove_entry(value) { diff --git a/crates/rune-alloc/src/iter/ext.rs b/crates/rune-alloc/src/iter/ext.rs index cc50105d7..1993e870a 100644 --- a/crates/rune-alloc/src/iter/ext.rs +++ b/crates/rune-alloc/src/iter/ext.rs @@ -86,10 +86,10 @@ pub trait IteratorExt: Iterator + self::sealed::Sealed { /// assert_eq!(v_map, [1, 2, 3]); /// # Ok::<_, rune::alloc::Error>(()) /// ``` - fn try_cloned<'a, T: 'a>(self) -> TryCloned + fn try_cloned<'a, T>(self) -> TryCloned where Self: Sized + Iterator, - T: TryClone, + T: 'a + TryClone, { TryCloned::new(self) } diff --git a/crates/rune/src/compile/context.rs b/crates/rune/src/compile/context.rs index 133ad95e5..cd9fe2e27 100644 --- a/crates/rune/src/compile/context.rs +++ b/crates/rune/src/compile/context.rs @@ -261,12 +261,12 @@ impl Context { } /// Iterate over known child components of the given name. - pub(crate) fn iter_components<'a, I: 'a>( + pub(crate) fn iter_components<'a, I>( &'a self, iter: I, ) -> alloc::Result> + 'a> where - I: IntoIterator, + I: 'a + IntoIterator, I::Item: IntoComponent, { self.names.iter_components(iter) diff --git a/crates/rune/src/compile/names.rs b/crates/rune/src/compile/names.rs index 65fd2c043..2388db31b 100644 --- a/crates/rune/src/compile/names.rs +++ b/crates/rune/src/compile/names.rs @@ -58,12 +58,12 @@ impl Names { /// Iterate over all known components immediately under the specified `iter` /// path. - pub(crate) fn iter_components<'a, I: 'a>( + pub(crate) fn iter_components<'a, I>( &'a self, iter: I, ) -> alloc::Result> + 'a> where - I: IntoIterator, + I: 'a + IntoIterator, I::Item: IntoComponent, { let iter = if let Some(current) = self.find_node(iter)? { diff --git a/crates/rune/src/module/function_traits.rs b/crates/rune/src/module/function_traits.rs index d7a100f4a..306e96d4e 100644 --- a/crates/rune/src/module/function_traits.rs +++ b/crates/rune/src/module/function_traits.rs @@ -205,18 +205,18 @@ where VmResult::Ok((vm_try!(T::from_value(value)), Guard)) } -fn unsafe_to_ref<'a, T: ?Sized>(value: Value) -> VmResult<(&'a T, T::Guard)> +fn unsafe_to_ref<'a, T>(value: Value) -> VmResult<(&'a T, T::Guard)> where - T: UnsafeToRef, + T: ?Sized + UnsafeToRef, { // SAFETY: these are only locally used in this module, and we ensure that // the guard requirement is met. unsafe { T::unsafe_to_ref(value) } } -fn unsafe_to_mut<'a, T: ?Sized>(value: Value) -> VmResult<(&'a mut T, T::Guard)> +fn unsafe_to_mut<'a, T>(value: Value) -> VmResult<(&'a mut T, T::Guard)> where - T: UnsafeToMut, + T: ?Sized + UnsafeToMut, { // SAFETY: these are only locally used in this module, and we ensure that // the guard requirement is met. diff --git a/crates/rune/src/query/query.rs b/crates/rune/src/query/query.rs index 4630950ad..452ef8bb9 100644 --- a/crates/rune/src/query/query.rs +++ b/crates/rune/src/query/query.rs @@ -1139,12 +1139,12 @@ impl<'a, 'arena> Query<'a, 'arena> { } /// Iterate over known child components of the given name. - pub(crate) fn iter_components<'it, I: 'it>( + pub(crate) fn iter_components<'it, I>( &'it self, iter: I, ) -> alloc::Result> + 'it> where - I: IntoIterator, + I: 'it + IntoIterator, I::Item: IntoComponent, { self.inner.names.iter_components(iter) diff --git a/crates/rune/src/runtime/bytes.rs b/crates/rune/src/runtime/bytes.rs index 05ba6e38e..1474789a1 100644 --- a/crates/rune/src/runtime/bytes.rs +++ b/crates/rune/src/runtime/bytes.rs @@ -16,7 +16,7 @@ use crate::runtime::{RawRef, Ref, UnsafeToRef, Value, ValueKind, VmErrorKind, Vm use crate::Any; /// A vector of bytes. -#[derive(Any, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Default, Any, PartialEq, Eq, PartialOrd, Ord, Hash)] #[rune(builtin, static_type = BYTES_TYPE)] pub struct Bytes { pub(crate) bytes: Vec, diff --git a/crates/rune/src/runtime/object.rs b/crates/rune/src/runtime/object.rs index 747a32cfe..fb3358a8a 100644 --- a/crates/rune/src/runtime/object.rs +++ b/crates/rune/src/runtime/object.rs @@ -159,19 +159,19 @@ impl Object { /// Returns a reference to the value corresponding to the key. #[inline] - pub fn get(&self, k: &Q) -> Option<&Value> + pub fn get(&self, k: &Q) -> Option<&Value> where String: borrow::Borrow, - Q: hash::Hash + cmp::Eq + cmp::Ord, + Q: ?Sized + hash::Hash + cmp::Eq + cmp::Ord, { self.inner.get(k) } /// Get the given value at the given index. - pub fn get_value(&self, k: &Q) -> VmResult> + pub fn get_value(&self, k: &Q) -> VmResult> where String: borrow::Borrow, - Q: hash::Hash + cmp::Eq + cmp::Ord, + Q: ?Sized + hash::Hash + cmp::Eq + cmp::Ord, T: FromValue, { let value = match self.inner.get(k) { @@ -184,20 +184,20 @@ impl Object { /// Returns a mutable reference to the value corresponding to the key. #[inline] - pub fn get_mut(&mut self, k: &Q) -> Option<&mut Value> + pub fn get_mut(&mut self, k: &Q) -> Option<&mut Value> where String: borrow::Borrow, - Q: hash::Hash + cmp::Eq + cmp::Ord, + Q: ?Sized + hash::Hash + cmp::Eq + cmp::Ord, { self.inner.get_mut(k) } /// Returns `true` if the map contains a value for the specified key. #[inline] - pub fn contains_key(&self, k: &Q) -> bool + pub fn contains_key(&self, k: &Q) -> bool where String: borrow::Borrow, - Q: hash::Hash + cmp::Eq + cmp::Ord, + Q: ?Sized + hash::Hash + cmp::Eq + cmp::Ord, { self.inner.contains_key(k) } @@ -205,10 +205,10 @@ impl Object { /// Removes a key from the map, returning the value at the key if the key /// was previously in the map. #[inline] - pub fn remove(&mut self, k: &Q) -> Option + pub fn remove(&mut self, k: &Q) -> Option where String: borrow::Borrow, - Q: hash::Hash + cmp::Eq + cmp::Ord, + Q: ?Sized + hash::Hash + cmp::Eq + cmp::Ord, { self.inner.remove(k) } diff --git a/crates/rune/src/runtime/value.rs b/crates/rune/src/runtime/value.rs index 7be5f5d99..8cd1f507d 100644 --- a/crates/rune/src/runtime/value.rs +++ b/crates/rune/src/runtime/value.rs @@ -336,19 +336,19 @@ impl Struct { } /// Get the given key in the object. - pub fn get(&self, k: &Q) -> Option<&Value> + pub fn get(&self, k: &Q) -> Option<&Value> where String: Borrow, - Q: hash::Hash + Eq + Ord, + Q: ?Sized + hash::Hash + Eq + Ord, { self.data.get(k) } /// Get the given mutable value by key in the object. - pub fn get_mut(&mut self, k: &Q) -> Option<&mut Value> + pub fn get_mut(&mut self, k: &Q) -> Option<&mut Value> where String: Borrow, - Q: hash::Hash + Eq + Ord, + Q: ?Sized + hash::Hash + Eq + Ord, { self.data.get_mut(k) } diff --git a/crates/rune/src/runtime/vec.rs b/crates/rune/src/runtime/vec.rs index f831d2244..8dd39dbc1 100644 --- a/crates/rune/src/runtime/vec.rs +++ b/crates/rune/src/runtime/vec.rs @@ -38,7 +38,7 @@ use self::iter::Iter; /// assert_eq!(None::, vec.get_value(2).into_result()?); /// # Ok::<_, rune::support::Error>(()) /// ``` -#[derive(Any)] +#[derive(Default, Any)] #[repr(transparent)] #[rune(builtin, static_type = VEC_TYPE)] #[rune(from_value = Value::into_vec, from_value_ref = Value::into_vec_ref, from_value_mut = Value::into_vec_mut)]