mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
address comments
This commit is contained in:
parent
fbb3f759e2
commit
cb5d7e344a
@ -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)
|
||||
* [`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)
|
||||
* [`manual_try_fold`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_try_fold)
|
||||
|
||||
|
||||
## `cognitive-complexity-threshold`
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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, 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
|
||||
(msrv: Option<String> = None),
|
||||
|
@ -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
|
||||
|
|
||||
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`
|
||||
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user