Skip to content

Commit b2fbc0b

Browse files
committed
---
yaml --- r: 63678 b: refs/heads/snap-stage3 c: e67c48a h: refs/heads/master v: v3
1 parent 804337b commit b2fbc0b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+140
-224
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: 64ee9668a2e3d4d75b859fd3bca1466a97fae2d8
4+
refs/heads/snap-stage3: e67c48a5912b85c286113e0d039aae85f18da1d7
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/tutorial.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,13 +1552,6 @@ fn each(v: &[int], op: &fn(v: &int)) {
15521552
}
15531553
~~~~
15541554

1555-
As an aside, the reason we pass in a *pointer* to an integer rather
1556-
than the integer itself is that this is how the actual `each()`
1557-
function for vectors works. `vec::each` though is a
1558-
[generic](#generics) function, so must be efficient to use for all
1559-
types. Passing the elements by pointer avoids copying potentially
1560-
large objects.
1561-
15621555
As a caller, if we use a closure to provide the final operator
15631556
argument, we can write it in a way that has a pleasant, block-like
15641557
structure.
@@ -1616,6 +1609,9 @@ To enable `debug!` logging, set the RUST_LOG environment variable to the name of
16161609

16171610
## For loops
16181611

1612+
> ***Note:*** The closure-based protocol used `for` loop is on the way out. The `for` loop will
1613+
> use iterator objects in the future instead.
1614+
16191615
The most common way to express iteration in Rust is with a `for`
16201616
loop. Like `do`, `for` is a nice syntax for describing control flow
16211617
with closures. Additionally, within a `for` loop, `break`, `loop`,
@@ -1640,7 +1636,16 @@ fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
16401636
And using this function to iterate over a vector:
16411637

16421638
~~~~
1643-
# use each = std::vec::each;
1639+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1640+
# let mut n = 0;
1641+
# while n < v.len() {
1642+
# if !op(&v[n]) {
1643+
# return false;
1644+
# }
1645+
# n += 1;
1646+
# }
1647+
# return true;
1648+
# }
16441649
each([2, 4, 8, 5, 16], |n| {
16451650
if *n % 2 != 0 {
16461651
println("found odd number!");
@@ -1656,7 +1661,16 @@ out of the loop, you just write `break`. To skip ahead
16561661
to the next iteration, write `loop`.
16571662

16581663
~~~~
1659-
# use each = std::vec::each;
1664+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1665+
# let mut n = 0;
1666+
# while n < v.len() {
1667+
# if !op(&v[n]) {
1668+
# return false;
1669+
# }
1670+
# n += 1;
1671+
# }
1672+
# return true;
1673+
# }
16601674
for each([2, 4, 8, 5, 16]) |n| {
16611675
if *n % 2 != 0 {
16621676
println("found odd number!");
@@ -1671,7 +1685,16 @@ normally allowed in closures, in a block that appears as the body of a
16711685
the enclosing function, not just the loop body.
16721686

16731687
~~~~
1674-
# use each = std::vec::each;
1688+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1689+
# let mut n = 0;
1690+
# while n < v.len() {
1691+
# if !op(&v[n]) {
1692+
# return false;
1693+
# }
1694+
# n += 1;
1695+
# }
1696+
# return true;
1697+
# }
16751698
fn contains(v: &[int], elt: int) -> bool {
16761699
for each(v) |x| {
16771700
if (*x == elt) { return true; }
@@ -1686,7 +1709,16 @@ In these situations it can be convenient to lean on Rust's
16861709
argument patterns to bind `x` to the actual value, not the pointer.
16871710

16881711
~~~~
1689-
# use each = std::vec::each;
1712+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1713+
# let mut n = 0;
1714+
# while n < v.len() {
1715+
# if !op(&v[n]) {
1716+
# return false;
1717+
# }
1718+
# n += 1;
1719+
# }
1720+
# return true;
1721+
# }
16901722
# fn contains(v: &[int], elt: int) -> bool {
16911723
for each(v) |&x| {
16921724
if (x == elt) { return true; }
@@ -1841,10 +1873,9 @@ vector consisting of the result of applying `function` to each element
18411873
of `vector`:
18421874

18431875
~~~~
1844-
# use std::vec;
18451876
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
18461877
let mut accumulator = ~[];
1847-
for vec::each(vector) |element| {
1878+
for vector.iter().advance |element| {
18481879
accumulator.push(function(element));
18491880
}
18501881
return accumulator;

branches/snap-stage3/src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn compose_and_run_compiler(
529529
let extra_link_args = ~[~"-L",
530530
aux_output_dir_name(config, testfile).to_str()];
531531

532-
for vec::each(props.aux_builds) |rel_ab| {
532+
for props.aux_builds.iter().advance |rel_ab| {
533533
let abs_ab = config.aux_base.push_rel(&Path(*rel_ab));
534534
let aux_args =
535535
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,

branches/snap-stage3/src/libextra/arc.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ mod tests {
521521
use core::cell::Cell;
522522
use core::comm;
523523
use core::task;
524+
use core::uint;
524525

525526
#[test]
526527
fn manually_share_arc() {
@@ -790,18 +791,20 @@ mod tests {
790791
}
791792
assert_eq!(*state, 42);
792793
*state = 31337;
794+
// FIXME: #7372: hits type inference bug with iterators
793795
// send to other readers
794-
for vec::each(reader_convos) |x| {
795-
match *x {
796+
for uint::range(0, reader_convos.len()) |i| {
797+
match reader_convos[i] {
796798
(ref rc, _) => rc.send(()),
797799
}
798800
}
799801
}
800802
let read_mode = arc.downgrade(write_mode);
801803
do (&read_mode).read |state| {
804+
// FIXME: #7372: hits type inference bug with iterators
802805
// complete handshake with other readers
803-
for vec::each(reader_convos) |x| {
804-
match *x {
806+
for uint::range(0, reader_convos.len()) |i| {
807+
match reader_convos[i] {
805808
(_, ref rp) => rp.recv(),
806809
}
807810
}

branches/snap-stage3/src/libextra/getopts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
418418
*/
419419
pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] {
420420
let mut acc: ~[~str] = ~[];
421-
for vec::each(opt_vals(mm, nm)) |v| {
421+
let r = opt_vals(mm, nm);
422+
for r.iter().advance |v| {
422423
match *v { Val(ref s) => acc.push(copy *s), _ => () }
423424
}
424-
return acc;
425+
acc
425426
}
426427

427428
/// Returns the string argument supplied to a matching option or none

branches/snap-stage3/src/libextra/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ impl Eq for Json {
11231123
&Object(ref d1) => {
11241124
if d0.len() == d1.len() {
11251125
let mut equal = true;
1126-
for d0.each |k, v0| {
1126+
for d0.iter().advance |(k, v0)| {
11271127
match d1.find(k) {
11281128
Some(v1) if v0 == v1 => { },
11291129
_ => { equal = false; break }
@@ -1186,12 +1186,12 @@ impl Ord for Json {
11861186
let mut d1_flat = ~[];
11871187

11881188
// FIXME #4430: this is horribly inefficient...
1189-
for d0.each |k, v| {
1189+
for d0.iter().advance |(k, v)| {
11901190
d0_flat.push((@copy *k, @copy *v));
11911191
}
11921192
d0_flat.qsort();
11931193

1194-
for d1.each |k, v| {
1194+
for d1.iter().advance |(k, v)| {
11951195
d1_flat.push((@copy *k, @copy *v));
11961196
}
11971197
d1_flat.qsort();
@@ -1326,7 +1326,7 @@ impl<A:ToJson> ToJson for ~[A] {
13261326
impl<A:ToJson + Copy> ToJson for HashMap<~str, A> {
13271327
fn to_json(&self) -> Json {
13281328
let mut d = HashMap::new();
1329-
for self.each |key, value| {
1329+
for self.iter().advance |(key, value)| {
13301330
d.insert(copy *key, value.to_json());
13311331
}
13321332
Object(~d)

branches/snap-stage3/src/libextra/net_url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
207207
let mut out = ~"";
208208
let mut first = true;
209209

210-
for m.each |key, values| {
210+
for m.iter().advance |(key, values)| {
211211
let key = encode_plus(*key);
212212

213213
for values.iter().advance |value| {

branches/snap-stage3/src/libextra/serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl<
710710
fn encode(&self, e: &mut E) {
711711
do e.emit_map(self.len()) |e| {
712712
let mut i = 0;
713-
for self.each |key, val| {
713+
for self.iter().advance |(key, val)| {
714714
e.emit_map_elt_key(i, |e| key.encode(e));
715715
e.emit_map_elt_val(i, |e| val.encode(e));
716716
i += 1;
@@ -744,7 +744,7 @@ impl<
744744
fn encode(&self, s: &mut S) {
745745
do s.emit_seq(self.len()) |s| {
746746
let mut i = 0;
747-
for self.each |e| {
747+
for self.iter().advance |e| {
748748
s.emit_seq_elt(i, |s| e.encode(s));
749749
i += 1;
750750
}

branches/snap-stage3/src/libextra/sync.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ mod tests {
10941094
};
10951095
assert!(result.is_err());
10961096
// child task must have finished by the time try returns
1097-
for vec::each(p.recv()) |p| { p.recv(); } // wait on all its siblings
1097+
let r = p.recv();
1098+
for r.iter().advance |p| { p.recv(); } // wait on all its siblings
10981099
do m.lock_cond |cond| {
10991100
let woken = cond.broadcast();
11001101
assert_eq!(woken, 0);

branches/snap-stage3/src/libextra/workcache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl WorkMap {
146146
impl<S:Encoder> Encodable<S> for WorkMap {
147147
fn encode(&self, s: &mut S) {
148148
let mut d = ~[];
149-
for self.each |k, v| {
149+
for self.iter().advance |(k, v)| {
150150
d.push((copy *k, copy *v))
151151
}
152152
sort::tim_sort(d);
@@ -320,7 +320,7 @@ impl TPrep for Prep {
320320
}
321321

322322
fn all_fresh(&self, cat: &str, map: &WorkMap) -> bool {
323-
for map.each |k, v| {
323+
for map.iter().advance |(k, v)| {
324324
if ! self.is_fresh(cat, k.kind, k.name, *v) {
325325
return false;
326326
}

branches/snap-stage3/src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn have_crate_data(cstore: &CStore, cnum: ast::crate_num) -> bool {
8686

8787
pub fn iter_crate_data(cstore: &CStore,
8888
i: &fn(ast::crate_num, @crate_metadata)) {
89-
for cstore.metas.each |&k, &v| {
89+
for cstore.metas.iter().advance |(&k, &v)| {
9090
i(k, v);
9191
}
9292
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ fn check_fn(
240240

241241
// Check kinds on free variables:
242242
do with_appropriate_checker(cx, fn_id) |chk| {
243-
for vec::each(*freevars::get_freevars(cx.tcx, fn_id)) |fv| {
243+
let r = freevars::get_freevars(cx.tcx, fn_id);
244+
for r.iter().advance |fv| {
244245
chk(cx, *fv);
245246
}
246247
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl LanguageItemCollector {
436436
}
437437

438438
pub fn check_completeness(&self) {
439-
for self.item_refs.each |&key, &item_ref| {
439+
for self.item_refs.iter().advance |(&key, &item_ref)| {
440440
match self.items.items[item_ref] {
441441
None => {
442442
self.session.err(fmt!("no item found for `%s`", key));

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl Context {
361361
}
362362

363363
fn lint_to_str(&self, lint: lint) -> &'static str {
364-
for self.dict.each |k, v| {
364+
for self.dict.iter().advance |(k, v)| {
365365
if v.lint == lint {
366366
return *k;
367367
}
@@ -742,7 +742,8 @@ fn check_item_ctypes(cx: &Context, it: @ast::item) {
742742

743743
fn check_foreign_fn(cx: &Context, decl: &ast::fn_decl) {
744744
let tys = vec::map(decl.inputs, |a| a.ty );
745-
for vec::each(vec::append_one(tys, decl.output)) |ty| {
745+
let r = vec::append_one(tys, decl.output);
746+
for r.iter().advance |ty| {
746747
check_ty(cx, *ty);
747748
}
748749
}
@@ -1171,7 +1172,7 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
11711172

11721173
// If we missed any lints added to the session, then there's a bug somewhere
11731174
// in the iteration code.
1174-
for tcx.sess.lints.each |_, v| {
1175+
for tcx.sess.lints.iter().advance |(_, v)| {
11751176
for v.iter().advance |t| {
11761177
match *t {
11771178
(lint, span, ref msg) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ pub fn determine_rp_in_crate(sess: Session,
948948
debug!("%s", {
949949
debug!("Region variance results:");
950950
let region_paramd_items = cx.region_paramd_items;
951-
for region_paramd_items.each |&key, &value| {
951+
for region_paramd_items.iter().advance |(&key, &value)| {
952952
debug!("item %? (%s) is parameterized with variance %?",
953953
key,
954954
ast_map::node_id_to_str(ast_map, key,

0 commit comments

Comments
 (0)