about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-06-16 13:01:08 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-06-16 18:13:45 +1000
commit53f6a4e9fbc3e8bb1fcf47ec3676c791892ea1b1 (patch)
tree22c6494217630c8ff12cf9b1e7fb6d2c1480e057
parentc989b79127c5062df0a64d8c383de93c82a3d9b7 (diff)
downloadrust-53f6a4e9fbc3e8bb1fcf47ec3676c791892ea1b1.tar.gz
rust-53f6a4e9fbc3e8bb1fcf47ec3676c791892ea1b1.zip
std: fix UnfoldrIterator cross-crate.
-rw-r--r--src/libstd/iterator.rs4
-rw-r--r--src/test/run-pass/unfoldr-cross-crate.rs34
2 files changed, 36 insertions, 2 deletions
diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs
index e65904a6899..a7450101fc0 100644
--- a/src/libstd/iterator.rs
+++ b/src/libstd/iterator.rs
@@ -788,8 +788,8 @@ impl<'self, A, St> UnfoldrIterator<'self, A, St> {
     /// Creates a new iterator with the specified closure as the "iterator
     /// function" and an initial state to eventually pass to the iterator
     #[inline]
-    pub fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
-        -> UnfoldrIterator<'self, A, St> {
+    pub fn new<'a>(f: &'a fn(&mut St) -> Option<A>, initial_state: St)
+        -> UnfoldrIterator<'a, A, St> {
         UnfoldrIterator {
             f: f,
             state: initial_state
diff --git a/src/test/run-pass/unfoldr-cross-crate.rs b/src/test/run-pass/unfoldr-cross-crate.rs
new file mode 100644
index 00000000000..4e98543ae82
--- /dev/null
+++ b/src/test/run-pass/unfoldr-cross-crate.rs
@@ -0,0 +1,34 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::iterator::*;
+
+// UnfoldrIterator had a bug with 'self that mean it didn't work
+// cross-crate
+
+fn main() {
+    fn count(st: &mut uint) -> Option<uint> {
+        if *st < 10 {
+            let ret = Some(*st);
+            *st += 1;
+            ret
+        } else {
+            None
+        }
+    }
+
+    let mut it = UnfoldrIterator::new(count, 0);
+    let mut i = 0;
+    for it.advance |counted| {
+        assert_eq!(counted, i);
+        i += 1;
+    }
+    assert_eq!(i, 10);
+}