Skip to content

Commit fd8aa9a

Browse files
committed
auto merge of #7177 : huonw/rust/unfold-fix, r=thestinger
2 parents ae23beb + 53f6a4e commit fd8aa9a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/libstd/iterator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,8 @@ impl<'self, A, St> UnfoldrIterator<'self, A, St> {
816816
/// Creates a new iterator with the specified closure as the "iterator
817817
/// function" and an initial state to eventually pass to the iterator
818818
#[inline]
819-
pub fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
820-
-> UnfoldrIterator<'self, A, St> {
819+
pub fn new<'a>(f: &'a fn(&mut St) -> Option<A>, initial_state: St)
820+
-> UnfoldrIterator<'a, A, St> {
821821
UnfoldrIterator {
822822
f: f,
823823
state: initial_state
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::iterator::*;
12+
13+
// UnfoldrIterator had a bug with 'self that mean it didn't work
14+
// cross-crate
15+
16+
fn main() {
17+
fn count(st: &mut uint) -> Option<uint> {
18+
if *st < 10 {
19+
let ret = Some(*st);
20+
*st += 1;
21+
ret
22+
} else {
23+
None
24+
}
25+
}
26+
27+
let mut it = UnfoldrIterator::new(count, 0);
28+
let mut i = 0;
29+
for it.advance |counted| {
30+
assert_eq!(counted, i);
31+
i += 1;
32+
}
33+
assert_eq!(i, 10);
34+
}

0 commit comments

Comments
 (0)