auto merge of #6223 : alexcrichton/rust/issue-6183, r=pcwalton
Closes #6183. The first commit changes the compiler's method of treating a `for` loop, and all the remaining commits are just dealing with the fallout. The biggest fallout was the `IterBytes` trait, although it's really a whole lot nicer now because all of the `iter_bytes_XX` methods are just and-ed together. Sadly there was a huge amount of stuff that's `cfg(stage0)` gated, but whoever lands the next snapshot is going to have a lot of fun deleting all this code!
This commit is contained in:
commit
3e0400fb86
73 changed files with 2948 additions and 309 deletions
|
|
@ -10,8 +10,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[allow(deprecated_mode)];
|
||||
|
||||
/*!
|
||||
|
||||
An implementation of the Graph500 Breadth First Search problem in Rust.
|
||||
|
|
@ -23,7 +21,7 @@ use std::arc;
|
|||
use std::time;
|
||||
use std::deque::Deque;
|
||||
use std::par;
|
||||
use core::hashmap::{HashMap, HashSet};
|
||||
use core::hashmap::HashSet;
|
||||
use core::int::abs;
|
||||
use core::rand::RngUtil;
|
||||
|
||||
|
|
@ -83,14 +81,13 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
|
|||
HashSet::new()
|
||||
};
|
||||
|
||||
do vec::each(edges) |e| {
|
||||
for vec::each(edges) |e| {
|
||||
match *e {
|
||||
(i, j) => {
|
||||
graph[i].insert(j);
|
||||
graph[j].insert(i);
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
do vec::map_consume(graph) |mut v| {
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@
|
|||
fn main() {
|
||||
fn baz(_x: &fn(y: int) -> int) {}
|
||||
for baz |_e| { } //~ ERROR A `for` loop iterator should expect a closure that returns `bool`
|
||||
//~^ ERROR expected `for` closure to return `bool`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
fn borrow(_v: &int) {}
|
||||
fn borrow_mut(_v: &mut int) {}
|
||||
fn cond() -> bool { fail!() }
|
||||
fn for_func(_f: &fn() -> bool) { fail!() }
|
||||
fn for_func(_f: &fn() -> bool) -> bool { fail!() }
|
||||
fn produce<T>() -> T { fail!(); }
|
||||
|
||||
fn inc(v: &mut ~int) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn not_bool(f: &fn(int) -> ~str) {}
|
||||
fn not_bool(f: &fn(int) -> ~str) -> bool {}
|
||||
|
||||
fn main() {
|
||||
for uint::range(0, 100000) |_i| { //~ ERROR A for-loop body must return (), but
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ fn uuid_random() -> uint { fail!(); }
|
|||
|
||||
fn main() {
|
||||
do uint::range(0, 100000) |_i| { //~ ERROR Do-block body must return bool, but
|
||||
}
|
||||
};
|
||||
// should get a more general message if the callback
|
||||
// doesn't return nil
|
||||
do uint::range(0, 100000) |_i| { //~ ERROR mismatched types
|
||||
~"str"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
do 5.times {} //~ ERROR Do-block body must return bool, but returns () here. Perhaps
|
||||
do 5.times {}; //~ ERROR Do-block body must return bool, but returns () here. Perhaps
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,5 @@
|
|||
|
||||
fn main() {
|
||||
for task::spawn { return true; } //~ ERROR A `for` loop iterator should expect a closure that
|
||||
//~^ ERROR expected `for` closure to return `bool`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ mod kitties {
|
|||
}
|
||||
|
||||
pub impl cat {
|
||||
priv fn nap(&self) { uint::range(1u, 10000u, |_i| false)}
|
||||
priv fn nap(&self) { uint::range(1u, 10000u, |_i| false); }
|
||||
}
|
||||
|
||||
pub fn cat(in_x : uint, in_y : int) -> cat {
|
||||
|
|
|
|||
|
|
@ -13,22 +13,18 @@
|
|||
// it.
|
||||
|
||||
trait iterable<A> {
|
||||
fn iterate(&self, blk: &fn(x: &A) -> bool);
|
||||
fn iterate(&self, blk: &fn(x: &A) -> bool) -> bool;
|
||||
}
|
||||
|
||||
impl<'self,A> iterable<A> for &'self [A] {
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) {
|
||||
for vec::each(*self) |e| {
|
||||
if !f(e) { break; }
|
||||
}
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) -> bool {
|
||||
vec::each(*self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A> iterable<A> for ~[A] {
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) {
|
||||
for vec::each(*self) |e| {
|
||||
if !f(e) { break; }
|
||||
}
|
||||
fn iterate(&self, f: &fn(x: &A) -> bool) -> bool {
|
||||
vec::each(*self, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ fn add_int(x: &mut Ints, v: int) {
|
|||
x.values <-> values;
|
||||
}
|
||||
|
||||
fn iter_ints(x: &Ints, f: &fn(x: &int) -> bool) {
|
||||
fn iter_ints(x: &Ints, f: &fn(x: &int) -> bool) -> bool {
|
||||
let l = x.values.len();
|
||||
uint::range(0, l, |i| f(&x.values[i]))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,25 +59,26 @@ impl<T> Mutable for cat<T> {
|
|||
}
|
||||
|
||||
impl<T> Map<int, T> for cat<T> {
|
||||
fn each<'a>(&'a self, f: &fn(&int, &'a T) -> bool) {
|
||||
fn each<'a>(&'a self, f: &fn(&int, &'a T) -> bool) -> bool {
|
||||
let mut n = int::abs(self.meows);
|
||||
while n > 0 {
|
||||
if !f(&n, &self.name) { break; }
|
||||
if !f(&n, &self.name) { return false; }
|
||||
n -= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
fn contains_key(&self, k: &int) -> bool { *k <= self.meows }
|
||||
|
||||
fn each_key(&self, f: &fn(v: &int) -> bool) {
|
||||
for self.each |k, _| { if !f(k) { break; } loop;};
|
||||
fn each_key(&self, f: &fn(v: &int) -> bool) -> bool {
|
||||
self.each(|k, _| f(k))
|
||||
}
|
||||
|
||||
fn each_value<'a>(&'a self, f: &fn(v: &'a T) -> bool) {
|
||||
for self.each |_, v| { if !f(v) { break; } loop;};
|
||||
fn each_value<'a>(&'a self, f: &fn(v: &'a T) -> bool) -> bool {
|
||||
self.each(|_, v| f(v))
|
||||
}
|
||||
|
||||
fn mutate_values(&mut self, _f: &fn(&int, &mut T) -> bool) {
|
||||
fn mutate_values(&mut self, _f: &fn(&int, &mut T) -> bool) -> bool {
|
||||
fail!(~"nope")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,14 +11,15 @@
|
|||
// no-reformat
|
||||
// Testing various forms of `do` and `for` with empty arg lists
|
||||
|
||||
fn f(f: &fn() -> bool) {
|
||||
fn f(f: &fn() -> bool) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
do f() || { true }
|
||||
do f() { true }
|
||||
do f || { true }
|
||||
do f { true }
|
||||
do f() || { true };
|
||||
do f() { true };
|
||||
do f || { true };
|
||||
do f { true };
|
||||
for f() || { }
|
||||
for f() { }
|
||||
for f || { }
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// Testing that we can drop the || in for/do exprs
|
||||
|
||||
fn f(f: @fn() -> bool) { }
|
||||
fn f(f: @fn() -> bool) -> bool { true }
|
||||
|
||||
fn d(f: @fn()) { }
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,13 @@
|
|||
|
||||
use core::cmp::Eq;
|
||||
|
||||
fn iter<T>(v: ~[T], it: &fn(&T) -> bool) {
|
||||
fn iter<T>(v: ~[T], it: &fn(&T) -> bool) -> bool {
|
||||
let mut i = 0u, l = v.len();
|
||||
while i < l {
|
||||
if !it(&v[i]) { break; }
|
||||
if !it(&v[i]) { return false; }
|
||||
i += 1u;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
fn find_pos<T:Eq + Copy + Clone>(n: T, h: ~[T]) -> Option<uint> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue