@@ -3198,9 +3198,15 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMutKey<'a, K, V, A> {
31983198 #[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
31993199 pub fn remove_next ( & mut self ) -> Option < ( K , V ) > {
32003200 let current = self . current . take ( ) ?;
3201+ if current. reborrow ( ) . next_kv ( ) . is_err ( ) {
3202+ self . current = Some ( current) ;
3203+ return None ;
3204+ }
32013205 let mut emptied_internal_root = false ;
32023206 let ( kv, pos) = current
32033207 . next_kv ( )
3208+ // This should be unwrap(), but that doesn't work because NodeRef
3209+ // doesn't implement Debug. The condition is checked above.
32043210 . ok ( ) ?
32053211 . remove_kv_tracking ( || emptied_internal_root = true , self . alloc . clone ( ) ) ;
32063212 self . current = Some ( pos) ;
@@ -3221,9 +3227,15 @@ impl<'a, K: Ord, V, A: Allocator + Clone> CursorMutKey<'a, K, V, A> {
32213227 #[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
32223228 pub fn remove_prev ( & mut self ) -> Option < ( K , V ) > {
32233229 let current = self . current . take ( ) ?;
3230+ if current. reborrow ( ) . next_back_kv ( ) . is_err ( ) {
3231+ self . current = Some ( current) ;
3232+ return None ;
3233+ }
32243234 let mut emptied_internal_root = false ;
32253235 let ( kv, pos) = current
32263236 . next_back_kv ( )
3237+ // This should be unwrap(), but that doesn't work because NodeRef
3238+ // doesn't implement Debug. The condition is checked above.
32273239 . ok ( ) ?
32283240 . remove_kv_tracking ( || emptied_internal_root = true , self . alloc . clone ( ) ) ;
32293241 self . current = Some ( pos) ;
0 commit comments