address comments

This commit is contained in:
Catherine 2023-06-29 02:26:45 -05:00
parent fbb3f759e2
commit cb5d7e344a
5 changed files with 11 additions and 10 deletions

View File

@ -150,6 +150,7 @@ The minimum rust version that the project supports
* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain) * [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain)
* [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds) * [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds)
* [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions) * [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions)
* [`manual_try_fold`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold)
## `cognitive-complexity-threshold` ## `cognitive-complexity-threshold`

View File

@ -46,7 +46,7 @@ pub(super) fn check<'tcx>(
cx, cx,
MANUAL_TRY_FOLD, MANUAL_TRY_FOLD,
fold_span, 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", "use `try_fold` instead",
format!("try_fold({init_snip}, {args_snip} ...)", ), format!("try_fold({init_snip}, {args_snip} ...)", ),
Applicability::HasPlaceholders, Applicability::HasPlaceholders,

View File

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

View File

@ -294,7 +294,7 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
/// ///
/// Suppress lints whenever the suggested change would cause breakage for other crates. /// Suppress lints whenever the suggested change would cause breakage for other crates.
(avoid_breaking_exported_api: bool = true), (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, TUPLE_ARRAY_CONVERSIONS. /// 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.
/// ///
/// The minimum rust version that the project supports /// The minimum rust version that the project supports
(msrv: Option<String> = None), (msrv: Option<String> = None),

View File

@ -1,4 +1,4 @@
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 --> $DIR/manual_try_fold.rs:61:10
| |
LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
@ -6,19 +6,19 @@ LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))
| |
= note: `-D clippy::manual-try-fold` implied by `-D warnings` = 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 --> $DIR/manual_try_fold.rs:65:10
| |
LL | .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32)); LL | .fold(NotOption(0i32, 0i32), |sum, i| NotOption(0i32, 0i32));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(..., |sum, i| ...)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 --> $DIR/manual_try_fold.rs:68:10
| |
LL | .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32)); LL | .fold(NotOptionButWorse(0i32), |sum, i| NotOptionButWorse(0i32));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `try_fold` instead: `try_fold(0i32, |sum, i| ...)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 --> $DIR/manual_try_fold.rs:98:10
| |
LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i)) LL | .fold(Some(0i32), |sum, i| sum?.checked_add(*i))