Skip to content

Commit cd8923d

Browse files
committed
Refactor excessive_for_each
1 parent ecbac7e commit cd8923d

13 files changed

+525
-406
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,6 @@ Released 2018-09-13
20562056
[`eq_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#eq_op
20572057
[`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op
20582058
[`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence
2059-
[`excessive_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_for_each
20602059
[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision
20612060
[`exhaustive_enums`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_enums
20622061
[`exhaustive_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_structs
@@ -2234,6 +2233,7 @@ Released 2018-09-13
22342233
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
22352234
[`needless_continue`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_continue
22362235
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
2236+
[`needless_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each
22372237
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
22382238
[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
22392239
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark

clippy_lints/src/iter_for_each.rs

Whitespace-only changes.

clippy_lints/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ mod needless_bool;
289289
mod needless_borrow;
290290
mod needless_borrowed_ref;
291291
mod needless_continue;
292+
mod needless_for_each;
292293
mod needless_pass_by_value;
293294
mod needless_question_mark;
294295
mod needless_update;
@@ -774,7 +775,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
774775
&methods::CLONE_DOUBLE_REF,
775776
&methods::CLONE_ON_COPY,
776777
&methods::CLONE_ON_REF_PTR,
777-
&methods::EXCESSIVE_FOR_EACH,
778778
&methods::EXPECT_FUN_CALL,
779779
&methods::EXPECT_USED,
780780
&methods::FILETYPE_IS_FILE,
@@ -861,6 +861,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
861861
&needless_borrow::NEEDLESS_BORROW,
862862
&needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
863863
&needless_continue::NEEDLESS_CONTINUE,
864+
&needless_for_each::NEEDLESS_FOR_EACH,
864865
&needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
865866
&needless_question_mark::NEEDLESS_QUESTION_MARK,
866867
&needless_update::NEEDLESS_UPDATE,
@@ -1040,6 +1041,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10401041
store.register_late_pass(|| box ptr_eq::PtrEq);
10411042
store.register_late_pass(|| box needless_bool::NeedlessBool);
10421043
store.register_late_pass(|| box needless_bool::BoolComparison);
1044+
store.register_late_pass(|| box needless_for_each::NeedlessForEach);
10431045
store.register_late_pass(|| box approx_const::ApproxConstant);
10441046
store.register_late_pass(|| box misc::MiscLints);
10451047
store.register_late_pass(|| box eta_reduction::EtaReduction);
@@ -1311,7 +1313,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13111313
LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM),
13121314
LintId::of(&mem_forget::MEM_FORGET),
13131315
LintId::of(&methods::CLONE_ON_REF_PTR),
1314-
LintId::of(&methods::EXCESSIVE_FOR_EACH),
13151316
LintId::of(&methods::EXPECT_USED),
13161317
LintId::of(&methods::FILETYPE_IS_FILE),
13171318
LintId::of(&methods::GET_UNWRAP),
@@ -1322,6 +1323,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13221323
LintId::of(&missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS),
13231324
LintId::of(&missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS),
13241325
LintId::of(&modulo_arithmetic::MODULO_ARITHMETIC),
1326+
LintId::of(&needless_for_each::NEEDLESS_FOR_EACH),
13251327
LintId::of(&panic_in_result_fn::PANIC_IN_RESULT_FN),
13261328
LintId::of(&panic_unimplemented::PANIC),
13271329
LintId::of(&panic_unimplemented::TODO),

clippy_lints/src/methods/excessive_for_each.rs

Lines changed: 0 additions & 122 deletions
This file was deleted.

clippy_lints/src/methods/mod.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -960,33 +960,6 @@ declare_clippy_lint! {
960960
"using `.skip(x).next()` on an iterator"
961961
}
962962

963-
declare_clippy_lint! {
964-
/// **What it does:** Checks for use of `.method(..).for_each(closure)` if the reciever of `.method(..)` doesn't
965-
/// implement `Iterator` and the return type of `.method(..)` implements `Iterator`.
966-
///
967-
/// **Why is this bad?** Excessive use of `for_each` reduces redability, using `for` loop is
968-
/// clearer and more concise.
969-
///
970-
/// **Known problems:** None.
971-
///
972-
/// **Example:**
973-
///
974-
/// ```rust
975-
/// let v = vec![0, 1, 2];
976-
/// v.iter().for_each(|elem| println!("{}", elem));
977-
/// ```
978-
/// Use instead:
979-
/// ```rust
980-
/// let v = vec![0, 1, 2];
981-
/// for elem in v.iter() {
982-
/// println!("{}", elem);
983-
/// }
984-
/// ```
985-
pub EXCESSIVE_FOR_EACH,
986-
restriction,
987-
"using `.iter().for_each(|x| {..})` when using `for` loop would work instead"
988-
}
989-
990963
declare_clippy_lint! {
991964
/// **What it does:** Checks for use of `.get().unwrap()` (or
992965
/// `.get_mut().unwrap`) on a standard library type which implements `Index`
@@ -1674,7 +1647,6 @@ impl_lint_pass!(Methods => [
16741647
ITER_NTH_ZERO,
16751648
BYTES_NTH,
16761649
ITER_SKIP_NEXT,
1677-
EXCESSIVE_FOR_EACH,
16781650
GET_UNWRAP,
16791651
STRING_EXTEND_CHARS,
16801652
ITER_CLONED_COLLECT,
@@ -1791,7 +1763,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17911763
["to_os_string", ..] => implicit_clone::check(cx, expr, sym::OsStr),
17921764
["to_path_buf", ..] => implicit_clone::check(cx, expr, sym::Path),
17931765
["to_vec", ..] => implicit_clone::check(cx, expr, sym::slice),
1794-
["for_each", ..] => excessive_for_each::lint(cx, expr, &arg_lists),
17951766
_ => {},
17961767
}
17971768

0 commit comments

Comments
 (0)