Skip to content

Commit 527fbbe

Browse files
committed
Refactor excessive_for_each
1 parent 5543c34 commit 527fbbe

13 files changed

+525
-406
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,6 @@ Released 2018-09-13
21922192
[`eq_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#eq_op
21932193
[`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op
21942194
[`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence
2195-
[`excessive_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_for_each
21962195
[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision
21972196
[`exhaustive_enums`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_enums
21982197
[`exhaustive_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_structs
@@ -2370,6 +2369,7 @@ Released 2018-09-13
23702369
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
23712370
[`needless_continue`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_continue
23722371
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
2372+
[`needless_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each
23732373
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
23742374
[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
23752375
[`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
@@ -291,6 +291,7 @@ mod needless_bool;
291291
mod needless_borrow;
292292
mod needless_borrowed_ref;
293293
mod needless_continue;
294+
mod needless_for_each;
294295
mod needless_pass_by_value;
295296
mod needless_question_mark;
296297
mod needless_update;
@@ -781,7 +782,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
781782
&methods::CLONE_DOUBLE_REF,
782783
&methods::CLONE_ON_COPY,
783784
&methods::CLONE_ON_REF_PTR,
784-
&methods::EXCESSIVE_FOR_EACH,
785785
&methods::EXPECT_FUN_CALL,
786786
&methods::EXPECT_USED,
787787
&methods::FILETYPE_IS_FILE,
@@ -868,6 +868,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
868868
&needless_borrow::NEEDLESS_BORROW,
869869
&needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
870870
&needless_continue::NEEDLESS_CONTINUE,
871+
&needless_for_each::NEEDLESS_FOR_EACH,
871872
&needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
872873
&needless_question_mark::NEEDLESS_QUESTION_MARK,
873874
&needless_update::NEEDLESS_UPDATE,
@@ -1046,6 +1047,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10461047
store.register_late_pass(|| box ptr_eq::PtrEq);
10471048
store.register_late_pass(|| box needless_bool::NeedlessBool);
10481049
store.register_late_pass(|| box needless_bool::BoolComparison);
1050+
store.register_late_pass(|| box needless_for_each::NeedlessForEach);
10491051
store.register_late_pass(|| box approx_const::ApproxConstant);
10501052
store.register_late_pass(|| box misc::MiscLints);
10511053
store.register_late_pass(|| box eta_reduction::EtaReduction);
@@ -1314,7 +1316,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13141316
LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM),
13151317
LintId::of(&mem_forget::MEM_FORGET),
13161318
LintId::of(&methods::CLONE_ON_REF_PTR),
1317-
LintId::of(&methods::EXCESSIVE_FOR_EACH),
13181319
LintId::of(&methods::EXPECT_USED),
13191320
LintId::of(&methods::FILETYPE_IS_FILE),
13201321
LintId::of(&methods::GET_UNWRAP),
@@ -1325,6 +1326,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13251326
LintId::of(&missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS),
13261327
LintId::of(&missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS),
13271328
LintId::of(&modulo_arithmetic::MODULO_ARITHMETIC),
1329+
LintId::of(&needless_for_each::NEEDLESS_FOR_EACH),
13281330
LintId::of(&panic_in_result_fn::PANIC_IN_RESULT_FN),
13291331
LintId::of(&panic_unimplemented::PANIC),
13301332
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
@@ -974,33 +974,6 @@ declare_clippy_lint! {
974974
"using `.skip(x).next()` on an iterator"
975975
}
976976

977-
declare_clippy_lint! {
978-
/// **What it does:** Checks for use of `.method(..).for_each(closure)` if the reciever of `.method(..)` doesn't
979-
/// implement `Iterator` and the return type of `.method(..)` implements `Iterator`.
980-
///
981-
/// **Why is this bad?** Excessive use of `for_each` reduces redability, using `for` loop is
982-
/// clearer and more concise.
983-
///
984-
/// **Known problems:** None.
985-
///
986-
/// **Example:**
987-
///
988-
/// ```rust
989-
/// let v = vec![0, 1, 2];
990-
/// v.iter().for_each(|elem| println!("{}", elem));
991-
/// ```
992-
/// Use instead:
993-
/// ```rust
994-
/// let v = vec![0, 1, 2];
995-
/// for elem in v.iter() {
996-
/// println!("{}", elem);
997-
/// }
998-
/// ```
999-
pub EXCESSIVE_FOR_EACH,
1000-
restriction,
1001-
"using `.iter().for_each(|x| {..})` when using `for` loop would work instead"
1002-
}
1003-
1004977
declare_clippy_lint! {
1005978
/// **What it does:** Checks for use of `.get().unwrap()` (or
1006979
/// `.get_mut().unwrap`) on a standard library type which implements `Index`
@@ -1688,7 +1661,6 @@ impl_lint_pass!(Methods => [
16881661
ITER_NTH_ZERO,
16891662
BYTES_NTH,
16901663
ITER_SKIP_NEXT,
1691-
EXCESSIVE_FOR_EACH,
16921664
GET_UNWRAP,
16931665
STRING_EXTEND_CHARS,
16941666
ITER_CLONED_COLLECT,
@@ -1835,7 +1807,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
18351807
["to_os_string", ..] => implicit_clone::check(cx, expr, sym::OsStr),
18361808
["to_path_buf", ..] => implicit_clone::check(cx, expr, sym::Path),
18371809
["to_vec", ..] => implicit_clone::check(cx, expr, sym::slice),
1838-
["for_each", ..] => excessive_for_each::lint(cx, expr, &arg_lists),
18391810
_ => {},
18401811
}
18411812

0 commit comments

Comments
 (0)