File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -710,18 +710,17 @@ where
710710 return None ;
711711 }
712712
713- let idx_opt = {
714- // work around borrowck limitations
715- let pred = & mut self . pred ;
716- self . v . iter ( ) . position ( |x| ( * pred) ( x) )
717- } ;
718- match idx_opt {
713+ match self . v . iter ( ) . position ( |x| ( self . pred ) ( x) ) {
719714 None => self . finish ( ) ,
720715 Some ( idx) => {
721- let tmp = mem:: replace ( & mut self . v , & mut [ ] ) ;
722- let ( head, tail) = tmp. split_at_mut ( idx) ;
723- self . v = & mut tail[ 1 ..] ;
724- Some ( head)
716+ let tmp = mem:: take ( & mut self . v ) ;
717+ // idx is the index of the element we are splitting on. We want to set self to the
718+ // region after idx, and return the subslice before and not including idx.
719+ // So first we split after idx
720+ let ( head, tail) = tmp. split_at_mut ( idx + 1 ) ;
721+ self . v = tail;
722+ // Then return the subslice up to but not including the found element
723+ Some ( & mut head[ ..idx] )
725724 }
726725 }
727726 }
You can’t perform that action at this time.
0 commit comments