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

ConsTuples::next_back is plain wrong #852

Closed
Philippe-Cholet opened this issue Jan 16, 2024 · 1 comment · Fixed by #853
Closed

ConsTuples::next_back is plain wrong #852

Philippe-Cholet opened this issue Jan 16, 2024 · 1 comment · Fixed by #853
Labels

Comments

@Philippe-Cholet
Copy link
Member

Philippe-Cholet commented Jan 16, 2024

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).

@phimuemue
Copy link
Member

phimuemue commented Jan 16, 2024

Nice catch! Yes, let’s remove it and see if anyone misses it. A wrong implementation does not help anybody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants