From e61f9782c805f246394f870902140bf32c897b7e Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Mon, 15 Mar 2021 12:01:39 +0900 Subject: [PATCH] Tweak a suggestion message of needless_for_each --- clippy_lints/src/needless_for_each.rs | 21 +++++++++------------ tests/ui/needless_for_each_unfixable.stderr | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/needless_for_each.rs b/clippy_lints/src/needless_for_each.rs index 727937354d6..2ea871990f1 100644 --- a/clippy_lints/src/needless_for_each.rs +++ b/clippy_lints/src/needless_for_each.rs @@ -10,7 +10,10 @@ use rustc_span::{source_map::Span, sym, Symbol}; use if_chain::if_chain; -use crate::utils::{has_iter_method, is_trait_method, snippet_with_applicability, span_lint_and_then}; +use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::is_trait_method; +use clippy_utils::source::snippet_with_applicability; +use clippy_utils::ty::has_iter_method; declare_clippy_lint! { /// **What it does:** Checks for usage of `for_each` that would be more simply written as a @@ -104,18 +107,12 @@ impl LateLintPass<'_> for NeedlessForEach { snippet_with_applicability(cx, body.value.span, "..", &mut applicability), ); - span_lint_and_then( - cx, - NEEDLESS_FOR_EACH, - stmt.span, - "needless use of `for_each`", - |diag| { - diag.span_suggestion(stmt.span, "try", sugg, applicability); - if let Some(ret_suggs) = ret_suggs { - diag.multipart_suggestion("try replacing `return` with `continue`", ret_suggs, applicability); - } + span_lint_and_then(cx, NEEDLESS_FOR_EACH, stmt.span, "needless use of `for_each`", |diag| { + diag.span_suggestion(stmt.span, "try", sugg, applicability); + if let Some(ret_suggs) = ret_suggs { + diag.multipart_suggestion("...and replace `return` with `continue`", ret_suggs, applicability); } - ) + }) } } } diff --git a/tests/ui/needless_for_each_unfixable.stderr b/tests/ui/needless_for_each_unfixable.stderr index bbb63fd8deb..8c4507d2328 100644 --- a/tests/ui/needless_for_each_unfixable.stderr +++ b/tests/ui/needless_for_each_unfixable.stderr @@ -20,7 +20,7 @@ LL | } else { LL | println!("{}", v); LL | } ... -help: try replacing `return` with `continue` +help: ...and replace `return` with `continue` | LL | continue; | ^^^^^^^^