auto merge of #15514 : luqmana/rust/die-advance-die, r=cmr

Closes #15492.
This commit is contained in:
bors 2014-07-09 23:51:27 +00:00
commit 1b8e671d74
12 changed files with 32 additions and 70 deletions

View File

@ -1426,18 +1426,14 @@ mod tests {
fn test_small_clear() {
let mut b = Bitv::with_capacity(14, true);
b.clear();
BitvSet::from_bitv(b).iter().advance(|i| {
fail!("found 1 at {:?}", i)
});
assert!(b.none());
}
#[test]
fn test_big_clear() {
let mut b = Bitv::with_capacity(140, true);
b.clear();
BitvSet::from_bitv(b).iter().advance(|i| {
fail!("found 1 at {:?}", i)
});
assert!(b.none());
}
#[test]
@ -1494,14 +1490,9 @@ mod tests {
assert!(b.insert(5));
assert!(b.insert(3));
let mut i = 0;
let expected = [3, 5, 11, 77];
a.intersection(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.intersection(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}
#[test]
@ -1518,14 +1509,9 @@ mod tests {
assert!(b.insert(3));
assert!(b.insert(200));
let mut i = 0;
let expected = [1, 5, 500];
a.difference(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}
#[test]
@ -1544,14 +1530,9 @@ mod tests {
assert!(b.insert(14));
assert!(b.insert(220));
let mut i = 0;
let expected = [1, 5, 11, 14, 220];
a.symmetric_difference(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.symmetric_difference(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}
#[test]
@ -1573,14 +1554,9 @@ mod tests {
assert!(b.insert(13));
assert!(b.insert(19));
let mut i = 0;
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160];
a.union(&b).advance(|x| {
assert_eq!(x, expected[i]);
i += 1;
true
});
assert_eq!(i, expected.len());
let actual = a.union(&b).collect::<Vec<uint>>();
assert_eq!(actual.as_slice(), expected.as_slice());
}
#[test]

View File

@ -1770,7 +1770,7 @@ mod test_set {
#[test]
fn test_intersection() {
fn check_intersection(a: &[int], b: &[int], expected: &[int]) {
check(a, b, expected, |x, y, f| x.intersection(y).advance(f))
check(a, b, expected, |x, y, f| x.intersection(y).all(f))
}
check_intersection([], [], []);
@ -1786,7 +1786,7 @@ mod test_set {
#[test]
fn test_difference() {
fn check_difference(a: &[int], b: &[int], expected: &[int]) {
check(a, b, expected, |x, y, f| x.difference(y).advance(f))
check(a, b, expected, |x, y, f| x.difference(y).all(f))
}
check_difference([], [], []);
@ -1804,7 +1804,7 @@ mod test_set {
fn test_symmetric_difference() {
fn check_symmetric_difference(a: &[int], b: &[int],
expected: &[int]) {
check(a, b, expected, |x, y, f| x.symmetric_difference(y).advance(f))
check(a, b, expected, |x, y, f| x.symmetric_difference(y).all(f))
}
check_symmetric_difference([], [], []);
@ -1819,7 +1819,7 @@ mod test_set {
fn test_union() {
fn check_union(a: &[int], b: &[int],
expected: &[int]) {
check(a, b, expected, |x, y, f| x.union(y).advance(f))
check(a, b, expected, |x, y, f| x.union(y).all(f))
}
check_union([], [], []);

View File

@ -435,9 +435,10 @@ pub trait Iterator<A> {
///
/// # Example
///
/// ```rust
/// ```rust,ignore
/// range(0u, 5).advance(|x| {print!("{} ", x); true});
/// ```
#[deprecated = "use the `all` method instead"]
#[inline]
fn advance(&mut self, f: |A| -> bool) -> bool {
loop {

View File

@ -896,7 +896,7 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool)
*cont
};
ss.char_indices().advance(|x| machine(&mut cont, x));
ss.char_indices().all(|x| machine(&mut cont, x));
// Let the automaton 'run out' by supplying trailing whitespace
while cont && match state { B | C => true, A => false } {

View File

@ -207,12 +207,12 @@ impl<N,E> Graph<N,E> {
pub fn each_node<'a>(&'a self, f: |NodeIndex, &'a Node<N>| -> bool) -> bool {
//! Iterates over all edges defined in the graph.
self.nodes.iter().enumerate().advance(|(i, node)| f(NodeIndex(i), node))
self.nodes.iter().enumerate().all(|(i, node)| f(NodeIndex(i), node))
}
pub fn each_edge<'a>(&'a self, f: |EdgeIndex, &'a Edge<E>| -> bool) -> bool {
//! Iterates over all edges defined in the graph
self.edges.iter().enumerate().advance(|(i, edge)| f(EdgeIndex(i), edge))
self.edges.iter().enumerate().all(|(i, edge)| f(EdgeIndex(i), edge))
}
pub fn each_outgoing_edge<'a>(&'a self,

View File

@ -5149,7 +5149,7 @@ impl<'a> Resolver<'a> {
}
_ => {
let mut method_scope = false;
self.value_ribs.borrow().iter().rev().advance(|rib| {
self.value_ribs.borrow().iter().rev().all(|rib| {
let res = match *rib {
Rib { bindings: _, kind: MethodRibKind(_, _) } => true,
Rib { bindings: _, kind: ItemRibKind } => false,

View File

@ -3887,13 +3887,13 @@ pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> Rc<ty::TraitDef> {
pub fn each_attr(tcx: &ctxt, did: DefId, f: |&ast::Attribute| -> bool) -> bool {
if is_local(did) {
let item = tcx.map.expect_item(did.node);
item.attrs.iter().advance(|attr| f(attr))
item.attrs.iter().all(|attr| f(attr))
} else {
info!("getting foreign attrs");
let mut cont = true;
csearch::get_item_attrs(&tcx.sess.cstore, did, |attrs| {
if cont {
cont = attrs.iter().advance(|attr| f(attr));
cont = attrs.iter().all(|attr| f(attr));
}
});
info!("done");

View File

@ -87,24 +87,9 @@ static AbiDatas: &'static [AbiData] = &[
AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch},
];
/// Iterates through each of the defined ABIs.
fn each_abi(op: |abi: Abi| -> bool) -> bool {
AbiDatas.iter().advance(|abi_data| op(abi_data.abi))
}
/// Returns the ABI with the given name (if any).
pub fn lookup(name: &str) -> Option<Abi> {
let mut res = None;
each_abi(|abi| {
if name == abi.data().name {
res = Some(abi);
false
} else {
true
}
});
res
AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi)
}
pub fn all_names() -> Vec<&'static str> {

View File

@ -611,18 +611,18 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
match pat.node {
PatIdent(_, _, Some(ref p)) => walk_pat(&**p, it),
PatStruct(_, ref fields, _) => {
fields.iter().advance(|f| walk_pat(&*f.pat, |p| it(p)))
fields.iter().all(|field| walk_pat(&*field.pat, |p| it(p)))
}
PatEnum(_, Some(ref s)) | PatTup(ref s) => {
s.iter().advance(|p| walk_pat(&**p, |p| it(p)))
s.iter().all(|p| walk_pat(&**p, |p| it(p)))
}
PatBox(ref s) | PatRegion(ref s) => {
walk_pat(&**s, it)
}
PatVec(ref before, ref slice, ref after) => {
before.iter().advance(|p| walk_pat(&**p, |p| it(p))) &&
slice.iter().advance(|p| walk_pat(&**p, |p| it(p))) &&
after.iter().advance(|p| walk_pat(&**p, |p| it(p)))
before.iter().all(|p| walk_pat(&**p, |p| it(p))) &&
slice.iter().all(|p| walk_pat(&**p, |p| it(p))) &&
after.iter().all(|p| walk_pat(&**p, |p| it(p)))
}
PatMac(_) => fail!("attempted to analyze unexpanded pattern"),
PatWild | PatWildMulti | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |

View File

@ -12,7 +12,7 @@ use std::vec::Vec;
fn main() {
let a: Vec<int> = Vec::new();
a.iter().advance(|_| -> bool {
a.iter().all(|_| -> bool {
//~^ ERROR mismatched types
});
}

View File

@ -19,13 +19,13 @@ trait iterable<A> {
impl<'a,A> iterable<A> for &'a [A] {
fn iterate(&self, f: |x: &A| -> bool) -> bool {
self.iter().advance(f)
self.iter().all(f)
}
}
impl<A> iterable<A> for Vec<A> {
fn iterate(&self, f: |x: &A| -> bool) -> bool {
self.iter().advance(f)
self.iter().all(f)
}
}

View File

@ -24,7 +24,7 @@ fn add_int(x: &mut Ints, v: int) {
fn iter_ints(x: &Ints, f: |x: &int| -> bool) -> bool {
let l = x.values.len();
range(0u, l).advance(|i| f(x.values.get(i)))
range(0u, l).all(|i| f(x.values.get(i)))
}
pub fn main() {