Skip to content

Commit 03eba7f

Browse files
committed
clippy fixes
1 parent ddaf123 commit 03eba7f

File tree

5 files changed

+39
-72
lines changed

5 files changed

+39
-72
lines changed

library/alloc/src/collections/btree/map.rs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,10 @@ where
222222
#[stable(feature = "rust1", since = "1.0.0")]
223223
impl<K: Clone, V: Clone, A: Allocator + Clone> Clone for BTreeMap<K, V, A> {
224224
fn clone(&self) -> BTreeMap<K, V, A> {
225-
fn clone_subtree<'a, K: Clone, V: Clone, A: Allocator + Clone>(
225+
fn clone_subtree<'a, K: Clone + 'a, V: Clone + 'a, A: Allocator + Clone>(
226226
node: NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>,
227227
alloc: A,
228-
) -> BTreeMap<K, V, A>
229-
where
230-
K: 'a,
231-
V: 'a,
232-
{
228+
) -> BTreeMap<K, V, A> {
233229
match node.force() {
234230
Leaf(leaf) => {
235231
let mut out_tree = BTreeMap {
@@ -330,11 +326,13 @@ impl<K, A: Allocator + Clone> BTreeMap<K, SetValZST, A> {
330326
}
331327
}
332328

333-
pub(super) fn get_or_insert_with<Q: ?Sized, F>(&mut self, q: &Q, f: F) -> &K
329+
pub(super) fn get_or_insert_with<Q: ?Sized + Ord>(
330+
&mut self,
331+
q: &Q,
332+
f: impl FnOnce(&Q) -> K,
333+
) -> &K
334334
where
335335
K: Borrow<Q> + Ord,
336-
Q: Ord,
337-
F: FnOnce(&Q) -> K,
338336
{
339337
let (map, dormant_map) = DormantMutRef::new(self);
340338
let root_node =
@@ -708,10 +706,10 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
708706
/// assert_eq!(map.get(&2), None);
709707
/// ```
710708
#[stable(feature = "rust1", since = "1.0.0")]
711-
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
709+
pub fn get<Q>(&self, key: &Q) -> Option<&V>
712710
where
711+
Q: ?Sized + Ord,
713712
K: Borrow<Q> + Ord,
714-
Q: Ord,
715713
{
716714
let root_node = self.root.as_ref()?.reborrow();
717715
match root_node.search_tree(key) {
@@ -774,10 +772,10 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
774772
/// assert_eq!(map.get_key_value(&p), None);
775773
/// ```
776774
#[stable(feature = "map_get_key_value", since = "1.40.0")]
777-
pub fn get_key_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>
775+
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
778776
where
777+
Q: ?Sized + Ord,
779778
K: Borrow<Q> + Ord,
780-
Q: Ord,
781779
{
782780
let root_node = self.root.as_ref()?.reborrow();
783781
match root_node.search_tree(k) {
@@ -970,10 +968,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
970968
/// ```
971969
#[stable(feature = "rust1", since = "1.0.0")]
972970
#[cfg_attr(not(test), rustc_diagnostic_item = "btreemap_contains_key")]
973-
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
971+
pub fn contains_key<Q: ?Sized + Ord>(&self, key: &Q) -> bool
974972
where
975973
K: Borrow<Q> + Ord,
976-
Q: Ord,
977974
{
978975
self.get(key).is_some()
979976
}
@@ -997,10 +994,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
997994
/// ```
998995
// See `get` for implementation notes, this is basically a copy-paste with mut's added
999996
#[stable(feature = "rust1", since = "1.0.0")]
1000-
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V>
997+
pub fn get_mut<Q: ?Sized + Ord>(&mut self, key: &Q) -> Option<&mut V>
1001998
where
1002999
K: Borrow<Q> + Ord,
1003-
Q: Ord,
10041000
{
10051001
let root_node = self.root.as_mut()?.borrow_mut();
10061002
match root_node.search_tree(key) {
@@ -1099,10 +1095,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
10991095
/// ```
11001096
#[stable(feature = "rust1", since = "1.0.0")]
11011097
#[rustc_confusables("delete", "take")]
1102-
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V>
1098+
pub fn remove<Q: ?Sized + Ord>(&mut self, key: &Q) -> Option<V>
11031099
where
11041100
K: Borrow<Q> + Ord,
1105-
Q: Ord,
11061101
{
11071102
self.remove_entry(key).map(|(_, v)| v)
11081103
}
@@ -1124,10 +1119,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11241119
/// assert_eq!(map.remove_entry(&1), None);
11251120
/// ```
11261121
#[stable(feature = "btreemap_remove_entry", since = "1.45.0")]
1127-
pub fn remove_entry<Q: ?Sized>(&mut self, key: &Q) -> Option<(K, V)>
1122+
pub fn remove_entry<Q: ?Sized + Ord>(&mut self, key: &Q) -> Option<(K, V)>
11281123
where
11291124
K: Borrow<Q> + Ord,
1130-
Q: Ord,
11311125
{
11321126
let (map, dormant_map) = DormantMutRef::new(self);
11331127
let root_node = map.root.as_mut()?.borrow_mut();
@@ -1257,9 +1251,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
12571251
/// assert_eq!(Some((&5, &"b")), map.range(4..).next());
12581252
/// ```
12591253
#[stable(feature = "btree_range", since = "1.17.0")]
1260-
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<'_, K, V>
1254+
pub fn range<T: ?Sized + Ord, R>(&self, range: R) -> Range<'_, K, V>
12611255
where
1262-
T: Ord,
12631256
K: Borrow<T> + Ord,
12641257
R: RangeBounds<T>,
12651258
{
@@ -1297,9 +1290,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
12971290
/// }
12981291
/// ```
12991292
#[stable(feature = "btree_range", since = "1.17.0")]
1300-
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<'_, K, V>
1293+
pub fn range_mut<T: ?Sized + Ord, R>(&mut self, range: R) -> RangeMut<'_, K, V>
13011294
where
1302-
T: Ord,
13031295
K: Borrow<T> + Ord,
13041296
R: RangeBounds<T>,
13051297
{
@@ -2691,10 +2683,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
26912683
/// assert_eq!(cursor.peek_next(), Some((&1, &"a")));
26922684
/// ```
26932685
#[unstable(feature = "btree_cursors", issue = "107540")]
2694-
pub fn lower_bound<Q: ?Sized>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
2686+
pub fn lower_bound<Q: ?Sized + Ord>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
26952687
where
26962688
K: Borrow<Q> + Ord,
2697-
Q: Ord,
26982689
{
26992690
let root_node = match self.root.as_ref() {
27002691
None => return Cursor { current: None, root: None },
@@ -2744,10 +2735,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
27442735
/// assert_eq!(cursor.peek_next(), Some((&1, &mut "a")));
27452736
/// ```
27462737
#[unstable(feature = "btree_cursors", issue = "107540")]
2747-
pub fn lower_bound_mut<Q: ?Sized>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
2738+
pub fn lower_bound_mut<Q: ?Sized + Ord>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
27482739
where
27492740
K: Borrow<Q> + Ord,
2750-
Q: Ord,
27512741
{
27522742
let (root, dormant_root) = DormantMutRef::new(&mut self.root);
27532743
let root_node = match root.as_mut() {
@@ -2814,10 +2804,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
28142804
/// assert_eq!(cursor.peek_next(), None);
28152805
/// ```
28162806
#[unstable(feature = "btree_cursors", issue = "107540")]
2817-
pub fn upper_bound<Q: ?Sized>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
2807+
pub fn upper_bound<Q: ?Sized + Ord>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V>
28182808
where
28192809
K: Borrow<Q> + Ord,
2820-
Q: Ord,
28212810
{
28222811
let root_node = match self.root.as_ref() {
28232812
None => return Cursor { current: None, root: None },
@@ -2867,10 +2856,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
28672856
/// assert_eq!(cursor.peek_next(), None);
28682857
/// ```
28692858
#[unstable(feature = "btree_cursors", issue = "107540")]
2870-
pub fn upper_bound_mut<Q: ?Sized>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
2859+
pub fn upper_bound_mut<Q: ?Sized + Ord>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
28712860
where
28722861
K: Borrow<Q> + Ord,
2873-
Q: Ord,
28742862
{
28752863
let (root, dormant_root) = DormantMutRef::new(&mut self.root);
28762864
let root_node = match root.as_mut() {

library/alloc/src/collections/btree/navigate.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,12 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
261261
/// # Safety
262262
/// Unless `BorrowType` is `Immut`, do not use the handles to visit the same
263263
/// KV twice.
264-
unsafe fn find_leaf_edges_spanning_range<Q: ?Sized, R>(
264+
unsafe fn find_leaf_edges_spanning_range<Q: ?Sized + Ord, R: RangeBounds<Q>>(
265265
self,
266266
range: R,
267267
) -> LeafRange<BorrowType, K, V>
268268
where
269-
Q: Ord,
270269
K: Borrow<Q>,
271-
R: RangeBounds<Q>,
272270
{
273271
match self.search_tree_for_bifurcation(&range) {
274272
Err(_) => LeafRange::none(),
@@ -741,12 +739,11 @@ impl<BorrowType: marker::BorrowType, K, V>
741739
impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::LeafOrInternal> {
742740
/// Returns the leaf edge corresponding to the first point at which the
743741
/// given bound is true.
744-
pub(super) fn lower_bound<Q: ?Sized>(
742+
pub(super) fn lower_bound<Q: ?Sized + Ord>(
745743
self,
746744
mut bound: SearchBound<&Q>,
747745
) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>
748746
where
749-
Q: Ord,
750747
K: Borrow<Q>,
751748
{
752749
let mut node = self;
@@ -764,12 +761,11 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
764761

765762
/// Returns the leaf edge corresponding to the last point at which the
766763
/// given bound is true.
767-
pub(super) fn upper_bound<Q: ?Sized>(
764+
pub(super) fn upper_bound<Q: ?Sized + Ord>(
768765
self,
769766
mut bound: SearchBound<&Q>,
770767
) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>
771768
where
772-
Q: Ord,
773769
K: Borrow<Q>,
774770
{
775771
let mut node = self;

library/alloc/src/collections/btree/search.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
4646
///
4747
/// The result is meaningful only if the tree is ordered by key, like the tree
4848
/// in a `BTreeMap` is.
49-
pub(super) fn search_tree<Q: ?Sized>(
49+
pub(super) fn search_tree<Q: ?Sized + Ord>(
5050
mut self,
5151
key: &Q,
5252
) -> SearchResult<BorrowType, K, V, marker::LeafOrInternal, marker::Leaf>
5353
where
54-
Q: Ord,
5554
K: Borrow<Q>,
5655
{
5756
loop {
@@ -80,7 +79,7 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
8079
/// As a diagnostic service, panics if the range specifies impossible bounds.
8180
///
8281
/// The result is meaningful only if the tree is ordered by key.
83-
pub(super) fn search_tree_for_bifurcation<'r, Q: ?Sized, R>(
82+
pub(super) fn search_tree_for_bifurcation<'r, Q: ?Sized + Ord, R>(
8483
mut self,
8584
range: &'r R,
8685
) -> Result<
@@ -94,7 +93,6 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
9493
Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>,
9594
>
9695
where
97-
Q: Ord,
9896
K: Borrow<Q>,
9997
R: RangeBounds<Q>,
10098
{
@@ -192,12 +190,11 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
192190
///
193191
/// The result is meaningful only if the tree is ordered by key, like the tree
194192
/// in a `BTreeMap` is.
195-
pub(super) fn search_node<Q: ?Sized>(
193+
pub(super) fn search_node<Q: ?Sized + Ord>(
196194
self,
197195
key: &Q,
198196
) -> SearchResult<BorrowType, K, V, Type, Type>
199197
where
200-
Q: Ord,
201198
K: Borrow<Q>,
202199
{
203200
match unsafe { self.find_key_index(key, 0) } {
@@ -214,9 +211,8 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
214211
///
215212
/// # Safety
216213
/// `start_index` must be a valid edge index for the node.
217-
unsafe fn find_key_index<Q: ?Sized>(&self, key: &Q, start_index: usize) -> IndexResult
214+
unsafe fn find_key_index<Q: ?Sized + Ord>(&self, key: &Q, start_index: usize) -> IndexResult
218215
where
219-
Q: Ord,
220216
K: Borrow<Q>,
221217
{
222218
let node = self.reborrow();

0 commit comments

Comments
 (0)