Skip to content

Deprecate advance method on Iterators. #15514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 10 additions & 34 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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([], [], []);
Expand All @@ -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([], [], []);
Expand All @@ -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([], [], []);
Expand All @@ -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([], [], []);
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 1 addition & 16 deletions src/libsyntax/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_, _, _) |
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/liveness-issue-2163.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
4 changes: 2 additions & 2 deletions src/test/run-pass/assignability-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/borrowck-mut-uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down