Skip to content

ConsTuples::next_back is plain wrong #852

Closed
@Philippe-Cholet

Description

@Philippe-Cholet

I was re-considering specialize ConsTuples::rfold for #755 when I saw something obviously wrong:

impl<X, Iter, $($B),*> DoubleEndedIterator for ConsTuples<Iter, (($($B,)*), X)>
where Iter: DoubleEndedIterator<Item = (($($B,)*), X)>,
{
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next().map(|(($($B,)*), x)| ($($B,)* x, ))
}
}

self.iter.next() instead of self.iter.next_back() is one obvious bug here!

ConsTuples is an internal detail of the iproduct macro and the cartesian product does not implement DoubleEndedIterator (and it can't as currently defined) so this is not used inside the crate (and won't).
No one noticed (in 8 years) such an obvious error so it's very unlikely used outside of itertools, right?

I suggest we remove the implementation (breaking change?).
Or we could fix it, add a test (and specialize rfold).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions