Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Centri3 committed Jun 30, 2023
1 parent adf9715 commit 5f4b796
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/manual_try_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(super) fn check<'tcx>(
cx,
MANUAL_TRY_FOLD,
fold_span,
"you seem to be using `Iterator::fold` on a type that implements `Try`",
"usage of `Iterator::fold` on a type that implements `Try`",
"use `try_fold` instead",
format!("try_fold({init_snip}, {args_snip} ...)", ),
Applicability::HasPlaceholders,
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3292,10 +3292,10 @@ declare_clippy_lint! {
/// Checks for usage of `Iterator::fold` with a type that implements `Try`.
///
/// ### Why is this bad?
/// 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.
/// The code 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,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ define_Conf! {
///
/// Suppress lints whenever the suggested change would cause breakage for other crates.
(avoid_breaking_exported_api: bool = true),
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS.
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, MANUAL_TRY_FOLD.
///
/// The minimum rust version that the project supports
(msrv: Option<String> = None),
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/manual_try_fold.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
error: you seem to be using `Iterator::fold` on a type that implements `Try`
error: usage of `Iterator::fold` on a type that implements `Try`
--> $DIR/manual_try_fold.rs:61:10
|
LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)`
|
= note: `-D clippy::manual-try-fold` implied by `-D warnings`

error: you seem to be using `Iterator::fold` on a type that implements `Try`
error: usage of `Iterator::fold` on a type that implements `Try`
--> $DIR/manual_try_fold.rs:65:10
|
LL | .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(..., |sum, i| ...)`

error: you seem to be using `Iterator::fold` on a type that implements `Try`
error: usage of `Iterator::fold` on a type that implements `Try`
--> $DIR/manual_try_fold.rs:68:10
|
LL | .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)`

error: you seem to be using `Iterator::fold` on a type that implements `Try`
error: usage of `Iterator::fold` on a type that implements `Try`
--> $DIR/manual_try_fold.rs:98:10
|
LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
Expand Down

0 comments on commit 5f4b796

Please sign in to comment.