Skip to content

nth_back() for Zip returns wrong values #68536

Closed
@JohnTitor

Description

@JohnTitor

Assertions are successful in this code (playground):

let mut a = Vec::new();
let mut b = Vec::new();
let value = [1, 2, 3, 4, 5, 6]
    .iter()
    .cloned()
    .map(|n| {
        a.push(n);
        n * 10
    })
    .zip([2, 3, 4, 5, 6, 7, 8].iter().cloned().map(|n| {
        b.push(n * 100);
        n * 1000
    }))
    .nth_back(3);
assert_eq!(value, Some((30, 4000)));
assert_eq!(a, vec![6, 6, 5, 5, 4, 4, 3]);
assert_eq!(b, vec![800, 700, 700, 600, 600, 500, 500, 400]);

But later assertions are actually wrong (the second and third ones shouldn't double-count).
@matthewjasper pointed out it's a bug that exists in the current next_back implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-iteratorsArea: IteratorsC-bugCategory: This is a bug.P-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions