1- use core:: borrow:: Borrow ;
2- use core:: cmp:: Ordering ;
1+ use core:: cmp:: { Comparable , Ordering } ;
32use core:: error:: Error ;
43use core:: fmt:: { self , Debug } ;
54use core:: hash:: { Hash , Hasher } ;
@@ -333,20 +332,19 @@ impl<K, A: Allocator + Clone> BTreeMap<K, SetValZST, A> {
333332 }
334333 }
335334
336- pub ( super ) fn get_or_insert_with < Q : ? Sized , F > ( & mut self , q : & Q , f : F ) -> & K
335+ pub ( super ) fn get_or_insert_with < Q : Clone , F > ( & mut self , q : Q , f : F ) -> & K
337336 where
338- K : Borrow < Q > + Ord ,
339- Q : Ord ,
340- F : FnOnce ( & Q ) -> K ,
337+ K : Comparable < Q > + Ord ,
338+ F : FnOnce ( Q ) -> K ,
341339 {
342340 let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
343341 let root_node =
344342 map. root . get_or_insert_with ( || Root :: new ( ( * map. alloc ) . clone ( ) ) ) . borrow_mut ( ) ;
345- match root_node. search_tree ( q) {
343+ match root_node. search_tree ( q. clone ( ) ) {
346344 Found ( handle) => handle. into_kv_mut ( ) . 0 ,
347345 GoDown ( handle) => {
348- let key = f ( q) ;
349- assert ! ( * key. borrow ( ) == * q , "new value is not equal" ) ;
346+ let key = f ( q. clone ( ) ) ;
347+ assert ! ( key. compare ( q ) == Ordering :: Equal , "new value is not equal" ) ;
350348 VacantEntry {
351349 key,
352350 handle : Some ( handle) ,
@@ -716,10 +714,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
716714 /// assert_eq!(map.get(&2), None);
717715 /// ```
718716 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
719- pub fn get < Q : ? Sized > ( & self , key : & Q ) -> Option < & V >
717+ pub fn get < Q : Clone > ( & self , key : Q ) -> Option < & V >
720718 where
721- K : Borrow < Q > + Ord ,
722- Q : Ord ,
719+ K : Comparable < Q > + Ord ,
723720 {
724721 let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
725722 match root_node. search_tree ( key) {
@@ -782,10 +779,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
782779 /// assert_eq!(map.get_key_value(&p), None);
783780 /// ```
784781 #[ stable( feature = "map_get_key_value" , since = "1.40.0" ) ]
785- pub fn get_key_value < Q : ? Sized > ( & self , k : & Q ) -> Option < ( & K , & V ) >
782+ pub fn get_key_value < Q : Clone > ( & self , k : Q ) -> Option < ( & K , & V ) >
786783 where
787- K : Borrow < Q > + Ord ,
788- Q : Ord ,
784+ K : Comparable < Q > + Ord ,
789785 {
790786 let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
791787 match root_node. search_tree ( k) {
@@ -978,10 +974,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
978974 /// ```
979975 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
980976 #[ cfg_attr( not( test) , rustc_diagnostic_item = "btreemap_contains_key" ) ]
981- pub fn contains_key < Q : ? Sized > ( & self , key : & Q ) -> bool
977+ pub fn contains_key < Q : Clone > ( & self , key : Q ) -> bool
982978 where
983- K : Borrow < Q > + Ord ,
984- Q : Ord ,
979+ K : Comparable < Q > + Ord ,
985980 {
986981 self . get ( key) . is_some ( )
987982 }
@@ -1005,10 +1000,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
10051000 /// ```
10061001 // See `get` for implementation notes, this is basically a copy-paste with mut's added
10071002 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1008- pub fn get_mut < Q : ? Sized > ( & mut self , key : & Q ) -> Option < & mut V >
1003+ pub fn get_mut < Q : Clone > ( & mut self , key : Q ) -> Option < & mut V >
10091004 where
1010- K : Borrow < Q > + Ord ,
1011- Q : Ord ,
1005+ K : Comparable < Q > + Ord ,
10121006 {
10131007 let root_node = self . root . as_mut ( ) ?. borrow_mut ( ) ;
10141008 match root_node. search_tree ( key) {
@@ -1107,10 +1101,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11071101 /// ```
11081102 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
11091103 #[ rustc_confusables( "delete" , "take" ) ]
1110- pub fn remove < Q : ? Sized > ( & mut self , key : & Q ) -> Option < V >
1104+ pub fn remove < Q : Clone > ( & mut self , key : Q ) -> Option < V >
11111105 where
1112- K : Borrow < Q > + Ord ,
1113- Q : Ord ,
1106+ K : Comparable < Q > + Ord ,
11141107 {
11151108 self . remove_entry ( key) . map ( |( _, v) | v)
11161109 }
@@ -1132,10 +1125,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11321125 /// assert_eq!(map.remove_entry(&1), None);
11331126 /// ```
11341127 #[ stable( feature = "btreemap_remove_entry" , since = "1.45.0" ) ]
1135- pub fn remove_entry < Q : ? Sized > ( & mut self , key : & Q ) -> Option < ( K , V ) >
1128+ pub fn remove_entry < Q : Clone > ( & mut self , key : Q ) -> Option < ( K , V ) >
11361129 where
1137- K : Borrow < Q > + Ord ,
1138- Q : Ord ,
1130+ K : Comparable < Q > + Ord ,
11391131 {
11401132 let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
11411133 let root_node = map. root . as_mut ( ) ?. borrow_mut ( ) ;
@@ -1410,7 +1402,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
14101402 pub fn range < T : ?Sized , R > ( & self , range : R ) -> Range < ' _ , K , V >
14111403 where
14121404 T : Ord ,
1413- K : Borrow < T > + Ord ,
1405+ K : Comparable < & T > ,
14141406 R : RangeBounds < T > ,
14151407 {
14161408 if let Some ( root) = & self . root {
@@ -1450,7 +1442,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
14501442 pub fn range_mut < T : ?Sized , R > ( & mut self , range : R ) -> RangeMut < ' _ , K , V >
14511443 where
14521444 T : Ord ,
1453- K : Borrow < T > + Ord ,
1445+ K : Comparable < & T > ,
14541446 R : RangeBounds < T > ,
14551447 {
14561448 if let Some ( root) = & mut self . root {
@@ -1539,9 +1531,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
15391531 /// assert_eq!(b[&41], "e");
15401532 /// ```
15411533 #[ stable( feature = "btree_split_off" , since = "1.11.0" ) ]
1542- pub fn split_off < Q : ? Sized + Ord > ( & mut self , key : & Q ) -> Self
1534+ pub fn split_off < Q : Clone > ( & mut self , key : Q ) -> Self
15431535 where
1544- K : Borrow < Q > + Ord ,
1536+ K : Comparable < Q > + Ord ,
15451537 A : Clone ,
15461538 {
15471539 if self . is_empty ( ) {
@@ -2618,8 +2610,7 @@ impl<K: Debug, V: Debug, A: Allocator + Clone> Debug for BTreeMap<K, V, A> {
26182610#[ stable( feature = "rust1" , since = "1.0.0" ) ]
26192611impl < K , Q : ?Sized , V , A : Allocator + Clone > Index < & Q > for BTreeMap < K , V , A >
26202612where
2621- K : Borrow < Q > + Ord ,
2622- Q : Ord ,
2613+ K : Comparable < & Q > + Ord ,
26232614{
26242615 type Output = V ;
26252616
@@ -2870,10 +2861,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
28702861 /// assert_eq!(cursor.peek_next(), Some((&1, &"a")));
28712862 /// ```
28722863 #[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
2873- pub fn lower_bound < Q : ? Sized > ( & self , bound : Bound < & Q > ) -> Cursor < ' _ , K , V >
2864+ pub fn lower_bound < Q : Clone > ( & self , bound : Bound < Q > ) -> Cursor < ' _ , K , V >
28742865 where
2875- K : Borrow < Q > + Ord ,
2876- Q : Ord ,
2866+ K : Comparable < Q > + Ord ,
28772867 {
28782868 let root_node = match self . root . as_ref ( ) {
28792869 None => return Cursor { current : None , root : None } ,
@@ -2923,10 +2913,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
29232913 /// assert_eq!(cursor.peek_next(), Some((&1, &mut "a")));
29242914 /// ```
29252915 #[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
2926- pub fn lower_bound_mut < Q : ? Sized > ( & mut self , bound : Bound < & Q > ) -> CursorMut < ' _ , K , V , A >
2916+ pub fn lower_bound_mut < Q : Clone > ( & mut self , bound : Bound < Q > ) -> CursorMut < ' _ , K , V , A >
29272917 where
2928- K : Borrow < Q > + Ord ,
2929- Q : Ord ,
2918+ K : Comparable < Q > + Ord ,
29302919 {
29312920 let ( root, dormant_root) = DormantMutRef :: new ( & mut self . root ) ;
29322921 let root_node = match root. as_mut ( ) {
@@ -2993,10 +2982,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
29932982 /// assert_eq!(cursor.peek_next(), None);
29942983 /// ```
29952984 #[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
2996- pub fn upper_bound < Q : ? Sized > ( & self , bound : Bound < & Q > ) -> Cursor < ' _ , K , V >
2985+ pub fn upper_bound < Q : Clone > ( & self , bound : Bound < Q > ) -> Cursor < ' _ , K , V >
29972986 where
2998- K : Borrow < Q > + Ord ,
2999- Q : Ord ,
2987+ K : Comparable < Q > + Ord ,
30002988 {
30012989 let root_node = match self . root . as_ref ( ) {
30022990 None => return Cursor { current : None , root : None } ,
@@ -3046,10 +3034,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
30463034 /// assert_eq!(cursor.peek_next(), None);
30473035 /// ```
30483036 #[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
3049- pub fn upper_bound_mut < Q : ? Sized > ( & mut self , bound : Bound < & Q > ) -> CursorMut < ' _ , K , V , A >
3037+ pub fn upper_bound_mut < Q : Clone > ( & mut self , bound : Bound < Q > ) -> CursorMut < ' _ , K , V , A >
30503038 where
3051- K : Borrow < Q > + Ord ,
3052- Q : Ord ,
3039+ K : Comparable < Q > + Ord ,
30533040 {
30543041 let ( root, dormant_root) = DormantMutRef :: new ( & mut self . root ) ;
30553042 let root_node = match root. as_mut ( ) {
0 commit comments