Skip to content
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

std: fix UnfoldrIterator cross-crate. #7177

Closed
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions src/libstd/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/test/run-pass/unfoldr-cross-crate.rs
Original file line number Diff line number Diff line change
@@ -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);
}