-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
unnecessary_fold: suggest bool bitwise ops #17792
Copy link
Copy link
Open
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.good first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
Activity
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesCategory: Enhancement of lints, like adding more cases or adding help messagesD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.good first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Summary
The
unnecessary_foldlint suggests usinganyover, e.g.,fold(false, |acc, x| acc || x)because the former short-circuits. But whether or not short-circuiting is wanted depends, for example, iterators or fold closures may have side-effects. The previous example is therefore ambiguous because it uses the short-circuiting||op. It ought explicitly either short-circuit viaanyor use the non-short-circuiting|op.Alternative solution to the #3351 issue
Reproducer
Code:
Current output:
Desired output:
Suggest
.fold(false, |acc, x| acc | x)as the explicit non-short-circuiting method.Version
Additional Labels
No response