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 !any(==) and similar #1334

Open
mcarton opened this issue Nov 9, 2016 · 5 comments
Open

Lint !any(==) and similar #1334

mcarton opened this issue Nov 9, 2016 · 5 comments
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types

Comments

@mcarton
Copy link
Member

mcarton commented Nov 9, 2016

At work I have a VS plugin suggesting to change stuff like !foo.any(|bar| bar == baz) to foo.all(|bar| bar != baz). !any and !all can usually be simplified.
It would be nice if nonminimal_bool could suggest that too.

@mcarton mcarton added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages A-lint Area: New lints T-middle Type: Probably requires verifiying types labels Nov 9, 2016
@oli-obk
Copy link
Contributor

oli-obk commented Nov 9, 2016

actually !foo.any(|bar| bar == baz) requires fewer iterations than foo.all(|bar| bar != baz), so there's no trivial solution.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 9, 2016

hmm.. ok wait... my brain was afk apparently... ignore my previous statement

@killercup
Copy link
Member

Huh I think my brain is wired the same way as @oli-obk's because I too through any would short-circuit where all couldn't. Which is false because (spoiler alert) all short-circuits the first time the condition doesn't hold. (E.g., vec![1, 2, 3].iter().any(|&x| x == 2) stops and returns true after it sees the second item, and vec![1, 2, 3].iter().all(|&x| x == 2) stops and returns false on the second item.)

Just though I'd write that down for other people who might be wondering :)

@mcarton
Copy link
Member Author

mcarton commented Nov 10, 2016

any is basically ||, all is basically &&. We already suggest simplifications on || and && so this should be considered too.

@camsteffen
Copy link
Contributor

Personally I find !foo.any(|bar| bar == baz) to be cognitively simpler. My general rule is to defer "not" operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

4 participants