@@ -727,24 +727,22 @@ pub fn tp_new_wrapper(
727727 call_tp_new ( zelf, cls, args, vm)
728728}
729729
730- fn take_next_base ( mut bases : Vec < Vec < PyTypeRef > > ) -> ( Option < PyTypeRef > , Vec < Vec < PyTypeRef > > ) {
731- bases = bases. into_iter ( ) . filter ( |x| !x. is_empty ( ) ) . collect ( ) ;
732-
733- for base in & bases {
730+ fn take_next_base ( bases : & mut Vec < Vec < PyTypeRef > > ) -> Option < PyTypeRef > {
731+ for base in bases. iter ( ) {
734732 let head = base[ 0 ] . clone ( ) ;
735- if !( & bases) . iter ( ) . any ( |x| x[ 1 ..] . iter ( ) . any ( |x| x. is ( & head) ) ) {
733+ if !bases. iter ( ) . any ( |x| x[ 1 ..] . iter ( ) . any ( |x| x. is ( & head) ) ) {
736734 // Remove from other heads.
737- for item in & mut bases {
735+ for item in bases. iter_mut ( ) {
738736 if item[ 0 ] . is ( & head) {
739737 item. remove ( 0 ) ;
740738 }
741739 }
742740
743- return ( Some ( head) , bases ) ;
741+ return Some ( head) ;
744742 }
745743 }
746744
747- ( None , bases )
745+ None
748746}
749747
750748fn linearise_mro ( mut bases : Vec < Vec < PyTypeRef > > ) -> Result < Vec < PyTypeRef > , String > {
@@ -768,22 +766,19 @@ fn linearise_mro(mut bases: Vec<Vec<PyTypeRef>>) -> Result<Vec<PyTypeRef>, Strin
768766 }
769767
770768 let mut result = vec ! [ ] ;
771- loop {
772- if ( & bases) . iter ( ) . all ( Vec :: is_empty) {
773- break ;
774- }
775- let ( head, new_bases) = take_next_base ( bases) ;
776- let head = head. ok_or_else ( || {
769+ while !bases. is_empty ( ) {
770+ let head = take_next_base ( & mut bases) . ok_or_else ( || {
777771 // Take the head class of each class here. Now that we have reached the problematic bases.
778772 // Because this failed, we assume the lists cannot be empty.
779773 format ! (
780774 "Cannot create a consistent method resolution order (MRO) for bases {}" ,
781- new_bases . iter( ) . map( |x| x. first( ) . unwrap( ) ) . join ( ", " )
775+ bases . iter( ) . map( |x| x. first( ) . unwrap( ) ) . format ( ", " )
782776 )
783- } ) ;
777+ } ) ?;
778+
779+ result. push ( head) ;
784780
785- result. push ( head. unwrap ( ) ) ;
786- bases = new_bases;
781+ bases. retain ( |x| !x. is_empty ( ) ) ;
787782 }
788783 Ok ( result)
789784}
0 commit comments