# Clippy lint for \`a.iter().zip(b.iter()).all()\` =\> \`a.iter().eq(b.iter())\` =\> \`a.eq(&b)\`

**URL:** <https://internals.rust-lang.org/t/clippy-lint-for-a-iter-zip-b-iter-all-a-iter-eq-b-iter-a-eq-b/21856>\
**Category:** compiler\
**Created:** [November 12, 2024, 2:00pm UTC](https://internals.rust-lang.org/t/clippy-lint-for-a-iter-zip-b-iter-all-a-iter-eq-b-iter-a-eq-b/21856 "2024-11-12T14:00:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![snprajwal](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/snprajwal/32/12653_2.png) [@snprajwal](https://internals.rust-lang.org/u/snprajwal)\
**Post date:** [November 12, 2024, 2:00pm UTC](https://internals.rust-lang.org/t/clippy-lint-for-a-iter-zip-b-iter-all-a-iter-eq-b-iter-a-eq-b/21856/1 "2024-11-12T14:00:44Z")

</div>

I noticed this pattern in a codebase I was working with.

```rust
let a = vec![1, 2, 3];
let b = vec![4, 5, 6];
// The below three are equivalent
a.iter().zip(b.iter()).all(|(x, y)| x == y);
a.iter().eq(b.iter());
a.eq(&b);

```

As long as `a.len() == b.len()`, this should work. Am I missing something here? If the logic is sound, would it make sense to add this as a lint to clippy?

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [November 12, 2024, 3:16pm UTC](https://internals.rust-lang.org/t/clippy-lint-for-a-iter-zip-b-iter-all-a-iter-eq-b-iter-a-eq-b/21856/2 "2024-11-12T15:16:29Z")

</div>

I’m not sure how a clippy lint could notice the `a.len() == b.len()` case.

The latter 2 should indeed be equivalent though, and the latter should always be better; for example it can do a proper up-front length check.

So it seems resonable to lint against usage of `Iterator::eq` on (newly-created) slice and/or vector iterators.

---

<div class="post-metadata">

**Author:** ![binarycat](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/binarycat/32/12210_2.png) [@binarycat](https://internals.rust-lang.org/u/binarycat)\
**Post date:** [November 15, 2024, 10:18pm UTC](https://internals.rust-lang.org/t/clippy-lint-for-a-iter-zip-b-iter-all-a-iter-eq-b-iter-a-eq-b/21856/3 "2024-11-15T22:18:23Z")

</div>

The first one seems to check if either is a prefix of the other, which is distinct and something you may actually want to do.

---

<div class="post-metadata">

**Author:** ![snprajwal](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/snprajwal/32/12653_2.png) [@snprajwal](https://internals.rust-lang.org/u/snprajwal)\
**Post date:** [November 18, 2024, 6:57am UTC](https://internals.rust-lang.org/t/clippy-lint-for-a-iter-zip-b-iter-all-a-iter-eq-b-iter-a-eq-b/21856/4 "2024-11-18T06:57:54Z")

</div>

Yes indeed, which is why the constraint of both vectors having equal length is important for this reduction.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [May 12, 2026, 6:58am UTC](https://internals.rust-lang.org/t/clippy-lint-for-a-iter-zip-b-iter-all-a-iter-eq-b-iter-a-eq-b/21856/5 "2026-05-12T06:58:19Z")

</div>

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
