trailofbits / dylint

Run Rust lints from dynamic libraries

Home Page:https://blog.trailofbits.com/2021/11/09/write-rust-lints-without-forking-clippy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recommend `IntoIterator` over `Iterator` for argument types

smoelius opened this issue · comments

In most cases,* if a function requires an argument type to implement Iterator, the function could instead require the argument type to implement IntoIterator.

IntoIterator is implemented for types that implement Iterator. So the function would accept all the arguments it did before.

But, in addition, the function would accept things like slices, vectors, etc.

* The one exception I know of is when the Iterator bound is needed for another trait. Here is an example: https://github.com/trailofbits/necessist/blob/c17890cf085abbe1c376b75118c354c08f9a6d6f/core/src/core.rs#L406-L412

But for a first attempt, this lint could not fire whenever the type parameter appears in another trait bound.