-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Substitute logical folds to any() or all() #6827
Comments
Actually, the things are a bit more complicated. Maybe it should be moved to |
And one more note: some_iterator.map(| item | {
// a closure which returns bool
})
.fold(false, | acc, x| {
acc | x
}); Could be written as: some_iterator.any(| item | {
// a closure which returns bool
}); Or: some_iterator.map(| item | {
// a closure which returns bool
})
.fold(true, | acc, x| {
acc & x
}); Could be written as: some_iterator.all(| item | {
// a closure which returns bool
}); |
Isn't this |
Actually, it is. Didn't checked that. |
You are using bitwise operators |
Yes, |
@rustbot claim |
Add `needless_bitwise_bool` lint fixes #6827 fixes #1594 changelog: Add ``[`needless_bitwise_bool`]`` lint Creates a new `bitwise_bool` lint to convert `x & y` to `x && y` when both `x` and `y` are booleans. I also had to adjust thh `needless_bool` lint slightly, and fix a couple failing dogfood tests. I made it a correctness lint as per flip1995's comment [here](#3385 (comment)), from a previous WIP attempt at this lint.
Add `needless_bitwise_bool` lint fixes #6827 fixes #1594 changelog: Add ``[`needless_bitwise_bool`]`` lint Creates a new `bitwise_bool` lint to convert `x & y` to `x && y` when both `x` and `y` are booleans. I also had to adjust thh `needless_bool` lint slightly, and fix a couple failing dogfood tests. I made it a correctness lint as per flip1995's comment [here](#3385 (comment)), from a previous WIP attempt at this lint.
What it does
Some uses of
.fold()
can be substituted to existing methods on iterators like.all()
and.any()
.Categories (optional)
clippy::complexity
What is the advantage of the recommended code over the original code
.any()
and.all()
are short-circuiting (see the docs)Drawbacks
None.
Examples
all
:Could be written as:
any
:Could be written as:
More over,
rustfmt
will remove curly brackets in the original code, so closure in the.any()
case will be formatted to completely unreadable and confusing|acc, x| acc | x
The text was updated successfully, but these errors were encountered: