Skip to content

Missing iterations #56883

Closed
Closed
@samueltardieu

Description

@samueltardieu
Contributor

The following code prints "foo" 4 times with stable and beta, but prints nothing with rustc 1.33.0-nightly (93c2f05 2018-12-15).

fn main() {
    std::iter::once(0).cycle().skip(1).take(4).for_each(|_| println!("foo"));
}

Replacing once() by something else or replacing for_each() with map() exhibits the same behaviour.

Activity

bluss

bluss commented on Dec 16, 2018

@bluss
Member

It looks like the try_fold impl for Cycle in commit fbe5aa5 is is not correct, this is probably the cause. PR #56630

samueltardieu

samueltardieu commented on Dec 16, 2018

@samueltardieu
ContributorAuthor

Indeed, it looks like if you try to fold after you have just exhausted a copy of your original iterator, you are out of luck and will exit immediately with the initial value.

added a commit that references this issue on Dec 17, 2018

Auto merge of #56904 - sinkuu:cycle_fold, r=bluss

adbfec2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @samueltardieu@bluss

        Issue actions

          Missing iterations · Issue #56883 · rust-lang/rust