Skip to content

Commit

Permalink
Refactor excessive_for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Mar 31, 2021
1 parent 5543c34 commit 527fbbe
Show file tree
Hide file tree
Showing 13 changed files with 525 additions and 406 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2192,7 +2192,6 @@ Released 2018-09-13
[`eq_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#eq_op
[`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op
[`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence
[`excessive_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_for_each
[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision
[`exhaustive_enums`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_enums
[`exhaustive_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#exhaustive_structs
Expand Down Expand Up @@ -2370,6 +2369,7 @@ Released 2018-09-13
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
[`needless_continue`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_continue
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
[`needless_for_each`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_for_each
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
Expand Down
Empty file removed clippy_lints/src/iter_for_each.rs
Empty file.
6 changes: 4 additions & 2 deletions clippy_lints/src/lib.rs
Expand Up @@ -291,6 +291,7 @@ mod needless_bool;
mod needless_borrow;
mod needless_borrowed_ref;
mod needless_continue;
mod needless_for_each;
mod needless_pass_by_value;
mod needless_question_mark;
mod needless_update;
Expand Down Expand Up @@ -781,7 +782,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&methods::CLONE_DOUBLE_REF,
&methods::CLONE_ON_COPY,
&methods::CLONE_ON_REF_PTR,
&methods::EXCESSIVE_FOR_EACH,
&methods::EXPECT_FUN_CALL,
&methods::EXPECT_USED,
&methods::FILETYPE_IS_FILE,
Expand Down Expand Up @@ -868,6 +868,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&needless_borrow::NEEDLESS_BORROW,
&needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
&needless_continue::NEEDLESS_CONTINUE,
&needless_for_each::NEEDLESS_FOR_EACH,
&needless_pass_by_value::NEEDLESS_PASS_BY_VALUE,
&needless_question_mark::NEEDLESS_QUESTION_MARK,
&needless_update::NEEDLESS_UPDATE,
Expand Down Expand Up @@ -1046,6 +1047,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box ptr_eq::PtrEq);
store.register_late_pass(|| box needless_bool::NeedlessBool);
store.register_late_pass(|| box needless_bool::BoolComparison);
store.register_late_pass(|| box needless_for_each::NeedlessForEach);
store.register_late_pass(|| box approx_const::ApproxConstant);
store.register_late_pass(|| box misc::MiscLints);
store.register_late_pass(|| box eta_reduction::EtaReduction);
Expand Down Expand Up @@ -1314,7 +1316,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM),
LintId::of(&mem_forget::MEM_FORGET),
LintId::of(&methods::CLONE_ON_REF_PTR),
LintId::of(&methods::EXCESSIVE_FOR_EACH),
LintId::of(&methods::EXPECT_USED),
LintId::of(&methods::FILETYPE_IS_FILE),
LintId::of(&methods::GET_UNWRAP),
Expand All @@ -1325,6 +1326,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS),
LintId::of(&missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS),
LintId::of(&modulo_arithmetic::MODULO_ARITHMETIC),
LintId::of(&needless_for_each::NEEDLESS_FOR_EACH),
LintId::of(&panic_in_result_fn::PANIC_IN_RESULT_FN),
LintId::of(&panic_unimplemented::PANIC),
LintId::of(&panic_unimplemented::TODO),
Expand Down
122 changes: 0 additions & 122 deletions clippy_lints/src/methods/excessive_for_each.rs

This file was deleted.

29 changes: 0 additions & 29 deletions clippy_lints/src/methods/mod.rs
Expand Up @@ -974,33 +974,6 @@ declare_clippy_lint! {
"using `.skip(x).next()` on an iterator"
}

declare_clippy_lint! {
/// **What it does:** Checks for use of `.method(..).for_each(closure)` if the reciever of `.method(..)` doesn't
/// implement `Iterator` and the return type of `.method(..)` implements `Iterator`.
///
/// **Why is this bad?** Excessive use of `for_each` reduces redability, using `for` loop is
/// clearer and more concise.
///
/// **Known problems:** None.
///
/// **Example:**
///
/// ```rust
/// let v = vec![0, 1, 2];
/// v.iter().for_each(|elem| println!("{}", elem));
/// ```
/// Use instead:
/// ```rust
/// let v = vec![0, 1, 2];
/// for elem in v.iter() {
/// println!("{}", elem);
/// }
/// ```
pub EXCESSIVE_FOR_EACH,
restriction,
"using `.iter().for_each(|x| {..})` when using `for` loop would work instead"
}

declare_clippy_lint! {
/// **What it does:** Checks for use of `.get().unwrap()` (or
/// `.get_mut().unwrap`) on a standard library type which implements `Index`
Expand Down Expand Up @@ -1688,7 +1661,6 @@ impl_lint_pass!(Methods => [
ITER_NTH_ZERO,
BYTES_NTH,
ITER_SKIP_NEXT,
EXCESSIVE_FOR_EACH,
GET_UNWRAP,
STRING_EXTEND_CHARS,
ITER_CLONED_COLLECT,
Expand Down Expand Up @@ -1835,7 +1807,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
["to_os_string", ..] => implicit_clone::check(cx, expr, sym::OsStr),
["to_path_buf", ..] => implicit_clone::check(cx, expr, sym::Path),
["to_vec", ..] => implicit_clone::check(cx, expr, sym::slice),
["for_each", ..] => excessive_for_each::lint(cx, expr, &arg_lists),
_ => {},
}

Expand Down

0 comments on commit 527fbbe

Please sign in to comment.