Skip to content

Commit d945543

Browse files
committed
Merge branch 'each-fn-kill' of https://github.com/huonw/rust into each-fn-kill
2 parents 18019a1 + 54d914a commit d945543

22 files changed

+77
-184
lines changed

src/libextra/sha1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use core::prelude::*;
2626

27+
use core::iterator::IteratorUtil;
2728
use core::str;
2829
use core::uint;
2930
use core::vec;
@@ -173,7 +174,7 @@ pub fn sha1() -> @Sha1 {
173174
fn mk_result(st: &mut Sha1State) -> ~[u8] {
174175
if !(*st).computed { pad_msg(st); (*st).computed = true; }
175176
let mut rs: ~[u8] = ~[];
176-
for vec::each_mut((*st).h) |ptr_hpart| {
177+
for st.h.mut_iter().advance |ptr_hpart| {
177178
let hpart = *ptr_hpart;
178179
let a = (hpart >> 24u32 & 0xFFu32) as u8;
179180
let b = (hpart >> 16u32 & 0xFFu32) as u8;

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use core::prelude::*;
2020

21+
use core::iterator::IteratorUtil;
2122
use core::cast;
2223
use core::io;
2324
use core::str;
@@ -895,7 +896,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
895896

896897
fn reset(&mut self, bits: &mut [uint]) {
897898
let e = if self.dfcx.oper.initial_value() {uint::max_value} else {0};
898-
for vec::each_mut(bits) |b| { *b = e; }
899+
for bits.mut_iter().advance |b| { *b = e; }
899900
}
900901

901902
fn add_to_entry_set(&mut self, id: ast::node_id, pred_bits: &[uint]) {

src/librustc/middle/kind.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use middle::typeck;
1717
use util::ppaux::{Repr, ty_to_str};
1818
use util::ppaux::UserString;
1919

20+
use core::iterator::IteratorUtil;
2021
use core::vec;
2122
use syntax::ast::*;
2223
use syntax::attr::attrs_contains_name;
@@ -268,7 +269,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
268269
ts.repr(cx.tcx),
269270
type_param_defs.repr(cx.tcx));
270271
}
271-
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
272+
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
272273
check_bounds(cx, type_parameter_id, e.span, ty, type_param_def)
273274
}
274275
}
@@ -309,7 +310,7 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
309310
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
310311
let type_param_defs =
311312
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
312-
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
313+
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
313314
check_bounds(cx, aty.id, aty.span, ty, type_param_def)
314315
}
315316
}

src/librustc/middle/trans/inline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use middle::trans::common::*;
1919
use middle::ty;
2020
use util::ppaux::ty_to_str;
2121

22+
use core::iterator::IteratorUtil;
2223
use core::vec;
2324
use syntax::ast;
2425
use syntax::ast_map::path_name;
@@ -75,7 +76,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
7576
ast::item_enum(_, _) => {
7677
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
7778
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
78-
for vec::each2(*vs_here, *vs_there) |here, there| {
79+
for vs_here.iter().zip(vs_there.iter()).advance |(here, there)| {
7980
if there.id == fn_id { my_id = here.id.node; }
8081
ccx.external.insert(there.id, Some(here.id.node));
8182
}

src/librustc/middle/trans/type_use.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use middle::trans::inline;
3333
use middle::ty;
3434
use middle::typeck;
3535

36+
use core::iterator::IteratorUtil;
3637
use core::option::{Some, None};
3738
use core::uint;
3839
use core::vec;
@@ -264,7 +265,7 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
264265
for opt_static_did.each |&did| {
265266
for cx.ccx.tcx.node_type_substs.find_copy(&callee_id).each |ts| {
266267
let type_uses = type_uses_for(cx.ccx, did, ts.len());
267-
for vec::each2(*type_uses, *ts) |uses, subst| {
268+
for type_uses.iter().zip(ts.iter()).advance |(uses, subst)| {
268269
type_needs(cx, *uses, *subst)
269270
}
270271
}
@@ -302,7 +303,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
302303
for opt_ts.each |ts| {
303304
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get_copy(&e.id));
304305
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
305-
for vec::each2(*uses_for_ts, *ts) |uses, subst| {
306+
for uses_for_ts.iter().zip(ts.iter()).advance |(uses, subst)| {
306307
type_needs(cx, *uses, *subst)
307308
}
308309
}

src/librustc/middle/typeck/check/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use middle::typeck::check::{instantiate_path, lookup_def};
1818
use middle::typeck::check::{structure_of, valid_range_bounds};
1919
use middle::typeck::require_same_types;
2020

21+
use core::iterator::IteratorUtil;
2122
use core::hashmap::{HashMap, HashSet};
22-
use core::vec;
2323
use syntax::ast;
2424
use syntax::ast_util;
2525
use syntax::codemap::span;
@@ -232,7 +232,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path,
232232
233233
if !error_happened {
234234
for subpats.each |pats| {
235-
for vec::each2(*pats, arg_types) |subpat, arg_ty| {
235+
for pats.iter().zip(arg_types.iter()).advance |(subpat, arg_ty)| {
236236
check_pat(pcx, *subpat, *arg_ty);
237237
}
238238
}

src/librustc/middle/typeck/check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ use util::common::{block_query, indenter, loop_query};
110110
use util::ppaux::{bound_region_to_str};
111111
use util::ppaux;
112112

113+
114+
use core::iterator::IteratorUtil;
113115
use core::cast::transmute;
114116
use core::hashmap::HashMap;
115117
use core::result;
@@ -412,7 +414,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
412414
for opt_self_info.each |self_info| {
413415
fcx.write_ty(self_info.self_id, self_info.self_ty);
414416
}
415-
for vec::each2(decl.inputs, arg_tys) |input, arg| {
417+
for decl.inputs.iter().zip(arg_tys.iter()).advance |(input, arg)| {
416418
fcx.write_ty(input.id, *arg);
417419
}
418420

@@ -449,7 +451,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
449451
}
450452

451453
// Add formal parameters.
452-
for vec::each2(arg_tys, decl.inputs) |arg_ty, input| {
454+
for arg_tys.iter().zip(decl.inputs.iter()).advance |(arg_ty, input)| {
453455
// Create type variables for each argument.
454456
do pat_util::pat_bindings(tcx.def_map, input.pat)
455457
|_bm, pat_id, _sp, _path| {

src/librustc/middle/typeck/coherence.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ use syntax::visit::{Visitor, SimpleVisitor};
5454
use syntax::visit::{visit_mod};
5555
use util::ppaux::ty_to_str;
5656

57+
use core::iterator::IteratorUtil;
5758
use core::hashmap::{HashMap, HashSet};
5859
use core::old_iter;
5960
use core::result::Ok;
@@ -617,9 +618,9 @@ impl CoherenceChecker {
617618
// Check to ensure that each parameter binding respected its
618619
// kind bounds.
619620
for [ a, b ].each |result| {
620-
for vec::each2(result.type_variables,
621-
*result.type_param_defs)
622-
|ty_var, type_param_def|
621+
for result.type_variables.iter()
622+
.zip(result.type_param_defs.iter())
623+
.advance |(ty_var, type_param_def)|
623624
{
624625
if type_param_def.bounds.builtin_bounds.contains_elem(
625626
ty::BoundCopy)

src/libstd/iterator.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait IteratorUtil<A> {
5555
/// assert_eq!(it.next().get(), &1);
5656
/// assert!(it.next().is_none());
5757
/// ~~~
58-
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<Self, U>;
58+
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, Self, U>;
5959

6060
/// Creates an iterator which iterates over both this and the specified
6161
/// iterators simultaneously, yielding the two elements as pairs. When
@@ -73,7 +73,7 @@ pub trait IteratorUtil<A> {
7373
/// assert_eq!(it.next().get(), (&0, &1));
7474
/// assert!(it.next().is_none());
7575
/// ~~~
76-
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<Self, U>;
76+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<A, Self, B, U>;
7777

7878
// FIXME: #5898: should be called map
7979
/// Creates a new iterator which will apply the specified function to each
@@ -139,7 +139,7 @@ pub trait IteratorUtil<A> {
139139
/// assert_eq!(it.next().get(), (1, &200));
140140
/// assert!(it.next().is_none());
141141
/// ~~~
142-
fn enumerate(self) -> EnumerateIterator<Self>;
142+
fn enumerate(self) -> EnumerateIterator<A, Self>;
143143

144144
/// Creates an iterator which invokes the predicate on elements until it
145145
/// returns true. Once the predicate returns true, all further elements are
@@ -349,12 +349,12 @@ pub trait IteratorUtil<A> {
349349
/// In the future these will be default methods instead of a utility trait.
350350
impl<A, T: Iterator<A>> IteratorUtil<A> for T {
351351
#[inline(always)]
352-
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<T, U> {
352+
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<A, T, U> {
353353
ChainIterator{a: self, b: other, flag: false}
354354
}
355355

356356
#[inline(always)]
357-
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
357+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<A, T, B, U> {
358358
ZipIterator{a: self, b: other}
359359
}
360360

@@ -375,7 +375,7 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
375375
}
376376

377377
#[inline(always)]
378-
fn enumerate(self) -> EnumerateIterator<T> {
378+
fn enumerate(self) -> EnumerateIterator<A, T> {
379379
EnumerateIterator{iter: self, count: 0}
380380
}
381381

@@ -570,13 +570,14 @@ impl<A: Ord, T: Iterator<A>> OrdIterator<A> for T {
570570
}
571571

572572
/// An iterator which strings two iterators together
573-
pub struct ChainIterator<T, U> {
573+
// FIXME #6967: Dummy A parameter to get around type inference bug
574+
pub struct ChainIterator<A, T, U> {
574575
priv a: T,
575576
priv b: U,
576577
priv flag: bool
577578
}
578579

579-
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
580+
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<A, T, U> {
580581
#[inline]
581582
fn next(&mut self) -> Option<A> {
582583
if self.flag {
@@ -593,12 +594,13 @@ impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
593594
}
594595

595596
/// An iterator which iterates two other iterators simultaneously
596-
pub struct ZipIterator<T, U> {
597+
// FIXME #6967: Dummy A & B parameters to get around type inference bug
598+
pub struct ZipIterator<A, T, B, U> {
597599
priv a: T,
598600
priv b: U
599601
}
600602

601-
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<T, U> {
603+
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<A, T, B, U> {
602604
#[inline]
603605
fn next(&mut self) -> Option<(A, B)> {
604606
match (self.a.next(), self.b.next()) {
@@ -664,12 +666,13 @@ impl<'self, A, B, T: Iterator<A>> Iterator<B> for FilterMapIterator<'self, A, B,
664666
}
665667

666668
/// An iterator which yields the current count and the element during iteration
667-
pub struct EnumerateIterator<T> {
669+
// FIXME #6967: Dummy A parameter to get around type inference bug
670+
pub struct EnumerateIterator<A, T> {
668671
priv iter: T,
669672
priv count: uint
670673
}
671674

672-
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<T> {
675+
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<A, T> {
673676
#[inline]
674677
fn next(&mut self) -> Option<(uint, A)> {
675678
match self.iter.next() {
@@ -887,7 +890,7 @@ mod tests {
887890
let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60];
888891
let mut it = xs.iter().chain(ys.iter());
889892
let mut i = 0;
890-
for it.advance |&x: &uint| {
893+
for it.advance |&x| {
891894
assert_eq!(x, expected[i]);
892895
i += 1;
893896
}
@@ -896,7 +899,7 @@ mod tests {
896899
let ys = Counter::new(30u, 10).take(4);
897900
let mut it = xs.iter().transform(|&x| x).chain(ys);
898901
let mut i = 0;
899-
for it.advance |x: uint| {
902+
for it.advance |x| {
900903
assert_eq!(x, expected[i]);
901904
i += 1;
902905
}
@@ -906,15 +909,15 @@ mod tests {
906909
#[test]
907910
fn test_filter_map() {
908911
let mut it = Counter::new(0u, 1u).take(10)
909-
.filter_map(|x: uint| if x.is_even() { Some(x*x) } else { None });
912+
.filter_map(|x| if x.is_even() { Some(x*x) } else { None });
910913
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
911914
}
912915

913916
#[test]
914917
fn test_iterator_enumerate() {
915918
let xs = [0u, 1, 2, 3, 4, 5];
916919
let mut it = xs.iter().enumerate();
917-
for it.advance |(i, &x): (uint, &uint)| {
920+
for it.advance |(i, &x)| {
918921
assert_eq!(i, x);
919922
}
920923
}
@@ -925,7 +928,7 @@ mod tests {
925928
let ys = [0u, 1, 2, 3, 5, 13];
926929
let mut it = xs.iter().take_while(|&x| *x < 15u);
927930
let mut i = 0;
928-
for it.advance |&x: &uint| {
931+
for it.advance |&x| {
929932
assert_eq!(x, ys[i]);
930933
i += 1;
931934
}
@@ -938,7 +941,7 @@ mod tests {
938941
let ys = [15, 16, 17, 19];
939942
let mut it = xs.iter().skip_while(|&x| *x < 15u);
940943
let mut i = 0;
941-
for it.advance |&x: &uint| {
944+
for it.advance |&x| {
942945
assert_eq!(x, ys[i]);
943946
i += 1;
944947
}

src/libstd/pipes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ bounded and unbounded protocols allows for less code duplication.
8787
use container::Container;
8888
use cast::{forget, transmute, transmute_copy};
8989
use either::{Either, Left, Right};
90+
use iterator::IteratorUtil;
9091
use kinds::Owned;
9192
use libc;
9293
use ops::Drop;
@@ -96,8 +97,7 @@ use unstable::intrinsics;
9697
use ptr;
9798
use ptr::RawPtr;
9899
use task;
99-
use vec;
100-
use vec::OwnedVector;
100+
use vec::{OwnedVector, MutableVector};
101101
use util::replace;
102102

103103
static SPIN_COUNT: uint = 0;
@@ -600,7 +600,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
600600

601601
let mut data_avail = false;
602602
let mut ready_packet = pkts.len();
603-
for vec::eachi_mut(pkts) |i, p| {
603+
for pkts.mut_iter().enumerate().advance |(i, p)| {
604604
unsafe {
605605
let p = &mut *p.header();
606606
let old = p.mark_blocked(this);
@@ -622,7 +622,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
622622
let event = wait_event(this) as *PacketHeader;
623623

624624
let mut pos = None;
625-
for vec::eachi_mut(pkts) |i, p| {
625+
for pkts.mut_iter().enumerate().advance |(i, p)| {
626626
if p.header() == event {
627627
pos = Some(i);
628628
break;
@@ -640,7 +640,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
640640

641641
debug!("%?", &mut pkts[ready_packet]);
642642

643-
for vec::each_mut(pkts) |p| {
643+
for pkts.mut_iter().advance |p| {
644644
unsafe {
645645
(*p.header()).unblock()
646646
}
@@ -853,7 +853,7 @@ pub fn select<T:Owned,Tb:Owned>(mut endpoints: ~[RecvPacketBuffered<T, Tb>])
853853
Option<T>,
854854
~[RecvPacketBuffered<T, Tb>]) {
855855
let mut endpoint_headers = ~[];
856-
for vec::each_mut(endpoints) |endpoint| {
856+
for endpoints.mut_iter().advance |endpoint| {
857857
endpoint_headers.push(endpoint.header());
858858
}
859859

src/libstd/prelude.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,3 @@ pub use io::{Reader, ReaderUtil, Writer, WriterUtil};
8282
// Reexported runtime types
8383
pub use comm::{stream, Port, Chan, GenericChan, GenericSmartChan, GenericPort, Peekable};
8484
pub use task::spawn;
85-

src/libstd/trie.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! An ordered map and set for integer keys implemented as a radix trie
1212
1313
use prelude::*;
14+
use iterator::IteratorUtil;
1415
use uint;
1516
use util::{swap, replace};
1617
use vec;
@@ -277,7 +278,7 @@ impl<T> TrieNode<T> {
277278
}
278279

279280
fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
280-
for vec::each_mut(self.children) |child| {
281+
for self.children.mut_iter().advance |child| {
281282
match *child {
282283
Internal(ref mut x) => if !x.mutate_values(f) {
283284
return false

0 commit comments

Comments
 (0)