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

Suggest replacing 'iter().any(|x| x == y)' with 'contains' where appropriate #2534

Open
TheIronBorn opened this issue Mar 15, 2018 · 2 comments
Labels
A-lint Area: New lints L-perf Lint: Belongs in the perf lint group L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types

Comments

@TheIronBorn
Copy link

TheIronBorn commented Mar 15, 2018

Particularly for str.chars().any or types with non-default implementations of SliceContains.

@TheIronBorn TheIronBorn changed the title Suggest replacing 'iter().any()' with 'contains' where appropriate Suggest replacing 'iter().any(|x| x == y)' with 'contains' where appropriate Mar 15, 2018
@oli-obk oli-obk added T-middle Type: Probably requires verifiying types A-lint Area: New lints L-perf Lint: Belongs in the perf lint group L-unnecessary Lint: Warn about unnecessary code labels Mar 16, 2018
@killercup
Copy link
Member

this is a good addition to the list in #2401 :)

@camsteffen
Copy link
Contributor

Some cases to include

// yoda condition
vec![1].iter().any(|&n| 1 == n);
// all not equal
vec![1].iter().all(|&n| n != 1);
// slice
|slice: &[u32]| slice.iter().any(|&n| n == 1);
// HashSet or BTreeSet
|set: HashSet<u32>| set.iter().any(|&n| n == 1);
// HashMap or BTreeMap keys
|map: HashMap<u32, u32>| map.keys().any(|&n| n == 1);

// more collections: VecDeque, LinkedList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-perf Lint: Belongs in the perf lint group L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

4 participants