@@ -2945,34 +2945,37 @@ impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for @[A] {
2945
2945
}
2946
2946
2947
2947
impl < ' self , A : Copy > old_iter:: CopyableNonstrictIter < A > for & ' self [ A ] {
2948
- fn each_val ( & const self , f : & fn ( A ) -> bool ) {
2948
+ fn each_val ( & const self , f : & fn ( A ) -> bool ) -> bool {
2949
2949
let mut i = 0 ;
2950
2950
while i < self . len ( ) {
2951
- if !f ( copy self [ i] ) { break ; }
2951
+ if !f ( copy self [ i] ) { return false ; }
2952
2952
i += 1 ;
2953
2953
}
2954
+ return true ;
2954
2955
}
2955
2956
}
2956
2957
2957
2958
// FIXME(#4148): This should be redundant
2958
2959
impl < A : Copy > old_iter:: CopyableNonstrictIter < A > for ~[ A ] {
2959
- fn each_val ( & const self , f : & fn ( A ) -> bool ) {
2960
+ fn each_val ( & const self , f : & fn ( A ) -> bool ) -> bool {
2960
2961
let mut i = 0 ;
2961
2962
while i < uniq_len ( self ) {
2962
- if !f ( copy self [ i] ) { break ; }
2963
+ if !f ( copy self [ i] ) { return false ; }
2963
2964
i += 1 ;
2964
2965
}
2966
+ return true ;
2965
2967
}
2966
2968
}
2967
2969
2968
2970
// FIXME(#4148): This should be redundant
2969
2971
impl < A : Copy > old_iter:: CopyableNonstrictIter < A > for @[ A ] {
2970
- fn each_val ( & const self , f : & fn ( A ) -> bool ) {
2972
+ fn each_val ( & const self , f : & fn ( A ) -> bool ) -> bool {
2971
2973
let mut i = 0 ;
2972
2974
while i < self . len ( ) {
2973
- if !f ( copy self [ i] ) { break ; }
2975
+ if !f ( copy self [ i] ) { return false ; }
2974
2976
i += 1 ;
2975
2977
}
2978
+ return true ;
2976
2979
}
2977
2980
}
2978
2981
@@ -4688,4 +4691,14 @@ mod tests {
4688
4691
i += 1 ;
4689
4692
}
4690
4693
}
4694
+
4695
+ #[ test]
4696
+ fn test_each_val ( ) {
4697
+ use old_iter:: CopyableNonstrictIter ;
4698
+ let mut i = 0 ;
4699
+ for [ 1 , 2 , 3 ] . each_val |v| {
4700
+ i += v;
4701
+ }
4702
+ assert ! ( i == 6 ) ;
4703
+ }
4691
4704
}
0 commit comments