Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Centri3 committed Jun 29, 2023
1 parent 947cbf7 commit 9bd994d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3290,10 +3290,15 @@ declare_clippy_lint! {
/// Checks for usage of `Iterator::fold` with a type that implements `Try`.
///
/// ### Why is this bad?
/// This is better represented with `try_fold`, but this has one major difference: It will
/// short-circuit on failure. *This is almost always what you want*. This can also open the door
/// for additional optimizations as well, as rustc can guarantee the function is never
/// called on `None`, `Err`, etc., alleviating otherwise necessary checks.
/// This should use `try_fold` instead, which short-circuits on failure, thus opening the door
/// for additional optimizations not possible with `fold` as rustc can guarantee the function is
/// never called on `None`, `Err`, etc., alleviating otherwise necessary checks. It's also
/// slightly more idiomatic.
///
/// ### Known issues
/// This lint doesn't take into account whether a function does something on the failure case,
/// i.e., whether short-circuiting will affect behavior. Refactoring to `try_fold` is not
/// desirable in those cases.
///
/// ### Example
/// ```rust
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_try_fold.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@aux-build:proc_macros.rs
//@aux-build:proc_macros.rs:proc-macro
#![allow(clippy::unnecessary_fold, unused)]
#![warn(clippy::manual_try_fold)]
#![feature(try_trait_v2)]
Expand Down

0 comments on commit 9bd994d

Please sign in to comment.