@@ -1328,7 +1328,10 @@ impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> {
13281328 None
13291329 } else {
13301330 self . length -= 1 ;
1331- unsafe { Some ( self . range . next_unchecked ( ) ) }
1331+ unsafe {
1332+ let ( k, v) = self . range . next_unchecked ( ) ;
1333+ Some ( ( k, v) ) // coerce k from `&mut K` to `&K`
1334+ }
13321335 }
13331336 }
13341337
@@ -1707,7 +1710,14 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
17071710 type Item = ( & ' a K , & ' a mut V ) ;
17081711
17091712 fn next ( & mut self ) -> Option < ( & ' a K , & ' a mut V ) > {
1710- if self . front == self . back { None } else { unsafe { Some ( self . next_unchecked ( ) ) } }
1713+ if self . front == self . back {
1714+ None
1715+ } else {
1716+ unsafe {
1717+ let ( k, v) = self . next_unchecked ( ) ;
1718+ Some ( ( k, v) ) // coerce k from `&mut K` to `&K`
1719+ }
1720+ }
17111721 }
17121722
17131723 fn last ( mut self ) -> Option < ( & ' a K , & ' a mut V ) > {
@@ -1716,16 +1726,15 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
17161726}
17171727
17181728impl < ' a , K , V > RangeMut < ' a , K , V > {
1719- unsafe fn next_unchecked ( & mut self ) -> ( & ' a K , & ' a mut V ) {
1729+ unsafe fn next_unchecked ( & mut self ) -> ( & ' a mut K , & ' a mut V ) {
17201730 let handle = ptr:: read ( & self . front ) ;
17211731
17221732 let mut cur_handle = match handle. right_kv ( ) {
17231733 Ok ( kv) => {
17241734 self . front = ptr:: read ( & kv) . right_edge ( ) ;
17251735 // Doing the descend invalidates the references returned by `into_kv_mut`,
17261736 // so we have to do this last.
1727- let ( k, v) = kv. into_kv_mut ( ) ;
1728- return ( k, v) ; // coerce k from `&mut K` to `&K`
1737+ return kv. into_kv_mut ( ) ;
17291738 }
17301739 Err ( last_edge) => {
17311740 let next_level = last_edge. into_node ( ) . ascend ( ) . ok ( ) ;
@@ -1739,8 +1748,7 @@ impl<'a, K, V> RangeMut<'a, K, V> {
17391748 self . front = first_leaf_edge ( ptr:: read ( & kv) . right_edge ( ) . descend ( ) ) ;
17401749 // Doing the descend invalidates the references returned by `into_kv_mut`,
17411750 // so we have to do this last.
1742- let ( k, v) = kv. into_kv_mut ( ) ;
1743- return ( k, v) ; // coerce k from `&mut K` to `&K`
1751+ return kv. into_kv_mut ( ) ;
17441752 }
17451753 Err ( last_edge) => {
17461754 let next_level = last_edge. into_node ( ) . ascend ( ) . ok ( ) ;
0 commit comments