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

lint None.into_iter()? #8529

Open
matthiaskrgr opened this issue Mar 12, 2022 · 0 comments
Open

lint None.into_iter()? #8529

matthiaskrgr opened this issue Mar 12, 2022 · 0 comments
Labels
A-lint Area: New lints

Comments

@matthiaskrgr
Copy link
Member

What it does

If we want to have something like an iterator that starts with certain item and then continues with another range of items, we can do something like chaining an iterator to an option:

Some(0).into_iter().chain(vec![1, 2, 3].into_iter())

Although it does not make a lot of sense, this works with None as well but the first item will not be saved in the iterator.

 None::<i32>.into_iter().chain(vec![1, 2, 3].into_iter())

I wonder if it makes sense to lint something like None.(into_)iter() and suggest std::iter::empty or removing the code entirely.

Lint Name

none_to_iter? none_into_iter?

Category

style, complexity

Advantage

No response

Drawbacks

No response

Example

 None::<i32>.into_iter().chain(vec![1, 2, 3].into_iter())

Could be written as:

vec![1,2,3].into_iter()
@matthiaskrgr matthiaskrgr added the A-lint Area: New lints label Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant