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

De Morgan any / all #8205

Open
gilescope opened this issue Dec 31, 2021 · 3 comments
Open

De Morgan any / all #8205

gilescope opened this issue Dec 31, 2021 · 3 comments
Labels
A-lint Area: New lints

Comments

@gilescope
Copy link

What it does

Would be good to suggest:

				if !incoming.iter().any(|e| e == old) {}

to

				if incoming.iter().all(|e| e != old) {}

(and the opposite)

This didn't seem to be in the complexity group, but similar others were so I think this is missing.

Lint Name

De Morgan any / all

Category

complexity

Advantage

simpler

Drawbacks

none

Example

if !incoming.iter().any(|e| e == old) {}

Could be written as:

if incoming.iter().all(|e| e != old) {}
@gilescope gilescope added the A-lint Area: New lints label Dec 31, 2021
@llogiq
Copy link
Contributor

llogiq commented Dec 31, 2021

I doubt it's that useful if the closure contains a comparison, as this way the only thing you add is a Not::not(_), thus making the code slightly longer. However, if the closure has a !p(e), linting would actually make sense.

@wigy-opensource-developer
Copy link
Contributor

I would argue that !...any(..) and !...all(..) are less intuitive, therefore more complex than ...all(!..) and ...any(!..), but you say, only !...any(!..) would trigger you? Maybe this needs a configuration parameter, or maybe these are 2 rules, one pedantic and one complexity?

I was looking around lints and could not find a similar rule for turning !.. && !.. into !(.. || ..) and its dual. If there was such a rule, it would also be useful for everyone for expressions like !(!.. && !..) and !(!.. || !..).

@camsteffen
Copy link
Contributor

This seems to be the same as #1334

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

4 participants