Skip to content

Commit cb5d7e3

Browse files
committed
address comments
1 parent fbb3f75 commit cb5d7e3

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

book/src/lint_configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ The minimum rust version that the project supports
150150
* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain)
151151
* [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds)
152152
* [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions)
153+
* [`manual_try_fold`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold)
153154

154155

155156
## `cognitive-complexity-threshold`

clippy_lints/src/methods/manual_try_fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(super) fn check<'tcx>(
4646
cx,
4747
MANUAL_TRY_FOLD,
4848
fold_span,
49-
"you seem to be using `Iterator::fold` on a type that implements `Try`",
49+
"usage of `Iterator::fold` on a type that implements `Try`",
5050
"use `try_fold` instead",
5151
format!("try_fold({init_snip}, {args_snip} ...)", ),
5252
Applicability::HasPlaceholders,

clippy_lints/src/methods/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3292,10 +3292,10 @@ declare_clippy_lint! {
32923292
/// Checks for usage of `Iterator::fold` with a type that implements `Try`.
32933293
///
32943294
/// ### Why is this bad?
3295-
/// This should use `try_fold` instead, which short-circuits on failure, thus opening the door
3296-
/// for additional optimizations not possible with `fold` as rustc can guarantee the function is
3297-
/// never called on `None`, `Err`, etc., alleviating otherwise necessary checks. It's also
3298-
/// slightly more idiomatic.
3295+
/// The code should use `try_fold` instead, which short-circuits on failure, thus opening the
3296+
/// door for additional optimizations not possible with `fold` as rustc can guarantee the
3297+
/// function is never called on `None`, `Err`, etc., alleviating otherwise necessary checks. It's
3298+
/// also slightly more idiomatic.
32993299
///
33003300
/// ### Known issues
33013301
/// This lint doesn't take into account whether a function does something on the failure case,

clippy_lints/src/utils/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ define_Conf! {
294294
///
295295
/// Suppress lints whenever the suggested change would cause breakage for other crates.
296296
(avoid_breaking_exported_api: bool = true),
297-
/// 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, TUPLE_ARRAY_CONVERSIONS.
297+
/// 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, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD.
298298
///
299299
/// The minimum rust version that the project supports
300300
(msrv: Option<String> = None),

tests/ui/manual_try_fold.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
error: you seem to be using `Iterator::fold` on a type that implements `Try`
1+
error: usage of `Iterator::fold` on a type that implements `Try`
22
--> $DIR/manual_try_fold.rs:61:10
33
|
44
LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)`
66
|
77
= note: `-D clippy::manual-try-fold` implied by `-D warnings`
88

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

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

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

0 commit comments

Comments
 (0)