Skip to content

Commit 1b6ef76

Browse files
committed
---
yaml --- r: 63084 b: refs/heads/snap-stage3 c: bc81d27 h: refs/heads/master v: v3
1 parent 68dfaa2 commit 1b6ef76

File tree

13 files changed

+117
-47
lines changed

13 files changed

+117
-47
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: f661a15b2bd5c2a9ea984c72c28caf970317d8a3
4+
refs/heads/snap-stage3: bc81d279fa04de7c956871ff6668d2a3d5e6d78c
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub enum const_val {
242242
pub fn eval_const_expr(tcx: middle::ty::ctxt, e: @expr) -> const_val {
243243
match eval_const_expr_partial(tcx, e) {
244244
Ok(ref r) => (/*bad*/copy *r),
245-
Err(ref s) => fail!(/*bad*/copy *s)
245+
Err(ref s) => tcx.sess.span_fatal(e.span, *s)
246246
}
247247
}
248248

branches/snap-stage3/src/librustc/middle/kind.rs

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

20-
use core::iterator::IteratorUtil;
2120
use core::vec;
2221
use syntax::ast::*;
2322
use syntax::attr::attrs_contains_name;
@@ -269,7 +268,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
269268
ts.repr(cx.tcx),
270269
type_param_defs.repr(cx.tcx));
271270
}
272-
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
271+
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
273272
check_bounds(cx, type_parameter_id, e.span, ty, type_param_def)
274273
}
275274
}
@@ -310,7 +309,7 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
310309
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
311310
let type_param_defs =
312311
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
313-
for ts.iter().zip(type_param_defs.iter()).advance |(&ty, type_param_def)| {
312+
for vec::each2(**ts, *type_param_defs) |&ty, type_param_def| {
314313
check_bounds(cx, aty.id, aty.span, ty, type_param_def)
315314
}
316315
}

branches/snap-stage3/src/librustc/middle/trans/inline.rs

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

22-
use core::iterator::IteratorUtil;
2322
use core::vec;
2423
use syntax::ast;
2524
use syntax::ast_map::path_name;
@@ -76,7 +75,7 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
7675
ast::item_enum(_, _) => {
7776
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
7877
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
79-
for vs_here.iter().zip(vs_there.iter()).advance |(here, there)| {
78+
for vec::each2(*vs_here, *vs_there) |here, there| {
8079
if there.id == fn_id { my_id = here.id.node; }
8180
ccx.external.insert(there.id, Some(here.id.node));
8281
}

branches/snap-stage3/src/librustc/middle/trans/type_use.rs

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

36-
use core::iterator::IteratorUtil;
3736
use core::option::{Some, None};
3837
use core::uint;
3938
use core::vec;
@@ -265,7 +264,7 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
265264
for opt_static_did.each |&did| {
266265
for cx.ccx.tcx.node_type_substs.find_copy(&callee_id).each |ts| {
267266
let type_uses = type_uses_for(cx.ccx, did, ts.len());
268-
for type_uses.iter().zip(ts.iter()).advance |(uses, subst)| {
267+
for vec::each2(*type_uses, *ts) |uses, subst| {
269268
type_needs(cx, *uses, *subst)
270269
}
271270
}
@@ -303,7 +302,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
303302
for opt_ts.each |ts| {
304303
let id = ast_util::def_id_of_def(cx.ccx.tcx.def_map.get_copy(&e.id));
305304
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
306-
for uses_for_ts.iter().zip(ts.iter()).advance |(uses, subst)| {
305+
for vec::each2(*uses_for_ts, *ts) |uses, subst| {
307306
type_needs(cx, *uses, *subst)
308307
}
309308
}

branches/snap-stage3/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;
2221
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 pats.iter().zip(arg_types.iter()).advance |(subpat, arg_ty)| {
235+
for vec::each2(*pats, arg_types) |subpat, arg_ty| {
236236
check_pat(pcx, *subpat, *arg_ty);
237237
}
238238
}

branches/snap-stage3/src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ 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;
115113
use core::cast::transmute;
116114
use core::hashmap::HashMap;
117115
use core::result;
@@ -414,7 +412,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
414412
for opt_self_info.each |self_info| {
415413
fcx.write_ty(self_info.self_id, self_info.self_ty);
416414
}
417-
for decl.inputs.iter().zip(arg_tys.iter()).advance |(input, arg)| {
415+
for vec::each2(decl.inputs, arg_tys) |input, arg| {
418416
fcx.write_ty(input.id, *arg);
419417
}
420418

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

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

branches/snap-stage3/src/librustc/middle/typeck/coherence.rs

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

57-
use core::iterator::IteratorUtil;
5857
use core::hashmap::{HashMap, HashSet};
5958
use core::old_iter;
6059
use core::result::Ok;
@@ -618,9 +617,9 @@ impl CoherenceChecker {
618617
// Check to ensure that each parameter binding respected its
619618
// kind bounds.
620619
for [ a, b ].each |result| {
621-
for result.type_variables.iter()
622-
.zip(result.type_param_defs.iter())
623-
.advance |(ty_var, type_param_def)|
620+
for vec::each2(result.type_variables,
621+
*result.type_param_defs)
622+
|ty_var, type_param_def|
624623
{
625624
if type_param_def.bounds.builtin_bounds.contains_elem(
626625
ty::BoundCopy)

branches/snap-stage3/src/libstd/iterator.rs

Lines changed: 18 additions & 21 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<A, Self, U>;
58+
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<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<A, Self, B, U>;
76+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<Self, 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<A, Self>;
142+
fn enumerate(self) -> EnumerateIterator<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<A, T, U> {
352+
fn chain<U: Iterator<A>>(self, other: U) -> ChainIterator<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<A, T, B, U> {
357+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, 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<A, T> {
378+
fn enumerate(self) -> EnumerateIterator<T> {
379379
EnumerateIterator{iter: self, count: 0}
380380
}
381381

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

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

580-
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<A, T, U> {
579+
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<T, U> {
581580
#[inline]
582581
fn next(&mut self) -> Option<A> {
583582
if self.flag {
@@ -594,13 +593,12 @@ impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for ChainIterator<A, T, U> {
594593
}
595594

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

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

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

675-
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<A, T> {
672+
impl<A, T: Iterator<A>> Iterator<(uint, A)> for EnumerateIterator<T> {
676673
#[inline]
677674
fn next(&mut self) -> Option<(uint, A)> {
678675
match self.iter.next() {
@@ -890,7 +887,7 @@ mod tests {
890887
let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60];
891888
let mut it = xs.iter().chain(ys.iter());
892889
let mut i = 0;
893-
for it.advance |&x| {
890+
for it.advance |&x: &uint| {
894891
assert_eq!(x, expected[i]);
895892
i += 1;
896893
}
@@ -899,7 +896,7 @@ mod tests {
899896
let ys = Counter::new(30u, 10).take(4);
900897
let mut it = xs.iter().transform(|&x| x).chain(ys);
901898
let mut i = 0;
902-
for it.advance |x| {
899+
for it.advance |x: uint| {
903900
assert_eq!(x, expected[i]);
904901
i += 1;
905902
}
@@ -909,15 +906,15 @@ mod tests {
909906
#[test]
910907
fn test_filter_map() {
911908
let mut it = Counter::new(0u, 1u).take(10)
912-
.filter_map(|x| if x.is_even() { Some(x*x) } else { None });
909+
.filter_map(|x: uint| if x.is_even() { Some(x*x) } else { None });
913910
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
914911
}
915912

916913
#[test]
917914
fn test_iterator_enumerate() {
918915
let xs = [0u, 1, 2, 3, 4, 5];
919916
let mut it = xs.iter().enumerate();
920-
for it.advance |(i, &x)| {
917+
for it.advance |(i, &x): (uint, &uint)| {
921918
assert_eq!(i, x);
922919
}
923920
}
@@ -928,7 +925,7 @@ mod tests {
928925
let ys = [0u, 1, 2, 3, 5, 13];
929926
let mut it = xs.iter().take_while(|&x| *x < 15u);
930927
let mut i = 0;
931-
for it.advance |&x| {
928+
for it.advance |&x: &uint| {
932929
assert_eq!(x, ys[i]);
933930
i += 1;
934931
}
@@ -941,7 +938,7 @@ mod tests {
941938
let ys = [15, 16, 17, 19];
942939
let mut it = xs.iter().skip_while(|&x| *x < 15u);
943940
let mut i = 0;
944-
for it.advance |&x| {
941+
for it.advance |&x: &uint| {
945942
assert_eq!(x, ys[i]);
946943
i += 1;
947944
}

branches/snap-stage3/src/libstd/vec.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,44 @@ pub fn eachi_reverse<'r,T>(v: &'r [T],
16661666
return true;
16671667
}
16681668

1669+
/**
1670+
* Iterates over two vectors simultaneously
1671+
*
1672+
* # Failure
1673+
*
1674+
* Both vectors must have the same length
1675+
*/
1676+
#[inline]
1677+
pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool {
1678+
assert_eq!(v1.len(), v2.len());
1679+
for uint::range(0u, v1.len()) |i| {
1680+
if !f(&v1[i], &v2[i]) {
1681+
return false;
1682+
}
1683+
}
1684+
return true;
1685+
}
1686+
1687+
/**
1688+
*
1689+
* Iterates over two vector with mutable.
1690+
*
1691+
* # Failure
1692+
*
1693+
* Both vectors must have the same length
1694+
*/
1695+
#[inline]
1696+
pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T],
1697+
f: &fn(u: &mut U, t: &mut T) -> bool) -> bool {
1698+
assert_eq!(v1.len(), v2.len());
1699+
for uint::range(0u, v1.len()) |i| {
1700+
if !f(&mut v1[i], &mut v2[i]) {
1701+
return false;
1702+
}
1703+
}
1704+
return true;
1705+
}
1706+
16691707
/**
16701708
* Iterate over all permutations of vector `v`.
16711709
*

branches/snap-stage3/src/libsyntax/ext/deriving/generic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ use opt_vec;
174174

175175
use core::uint;
176176
use core::vec;
177-
use core::iterator::IteratorUtil;
178177

179178
pub use self::ty::*;
180179
mod ty;
@@ -617,7 +616,7 @@ impl<'self> MethodDef<'self> {
617616
// make a series of nested matches, to destructure the
618617
// structs. This is actually right-to-left, but it shoudn't
619618
// matter.
620-
for self_args.iter().zip(patterns.iter()).advance |(&arg_expr, &pat)| {
619+
for vec::each2(self_args, patterns) |&arg_expr, &pat| {
621620
body = cx.expr_match(span, arg_expr,
622621
~[ cx.arm(span, ~[pat], body) ])
623622
}
@@ -952,7 +951,7 @@ fn create_struct_pattern(cx: @ExtCtxt,
952951
// must be nonempty to reach here
953952
let pattern = if struct_type == Record {
954953
let field_pats = do vec::build |push| {
955-
for subpats.iter().zip(ident_expr.iter()).advance |(&pat, &(id, _))| {
954+
for vec::each2(subpats, ident_expr) |&pat, &(id, _)| {
956955
// id is guaranteed to be Some
957956
push(ast::field_pat { ident: id.get(), pat: pat })
958957
}

branches/snap-stage3/src/test/bench/shootout-fannkuch-redux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::iterator::*;
21
use std::from_str::FromStr;
32
use std::i32::range;
43
use std::os;
@@ -30,8 +29,9 @@ fn fannkuch_redux(n: i32) -> i32 {
3029
r -= 1;
3130
}
3231

33-
for perm.mut_iter().zip(perm1.iter()).advance |(perm_i, perm1_i)| {
34-
*perm_i = *perm1_i;
32+
// XXX: Need each2_mut.
33+
for vec::eachi_mut(perm) |i, perm_i| {
34+
*perm_i = perm1.unsafe_get(i);
3535
}
3636

3737
let mut flips_count: i32 = 0;

0 commit comments

Comments
 (0)