Skip to content

Commit e61f978

Browse files
committed
Tweak a suggestion message of needless_for_each
1 parent bf1e3f7 commit e61f978

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

clippy_lints/src/needless_for_each.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use rustc_span::{source_map::Span, sym, Symbol};
1010

1111
use if_chain::if_chain;
1212

13-
use crate::utils::{has_iter_method, is_trait_method, snippet_with_applicability, span_lint_and_then};
13+
use clippy_utils::diagnostics::span_lint_and_then;
14+
use clippy_utils::is_trait_method;
15+
use clippy_utils::source::snippet_with_applicability;
16+
use clippy_utils::ty::has_iter_method;
1417

1518
declare_clippy_lint! {
1619
/// **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 {
104107
snippet_with_applicability(cx, body.value.span, "..", &mut applicability),
105108
);
106109

107-
span_lint_and_then(
108-
cx,
109-
NEEDLESS_FOR_EACH,
110-
stmt.span,
111-
"needless use of `for_each`",
112-
|diag| {
113-
diag.span_suggestion(stmt.span, "try", sugg, applicability);
114-
if let Some(ret_suggs) = ret_suggs {
115-
diag.multipart_suggestion("try replacing `return` with `continue`", ret_suggs, applicability);
116-
}
110+
span_lint_and_then(cx, NEEDLESS_FOR_EACH, stmt.span, "needless use of `for_each`", |diag| {
111+
diag.span_suggestion(stmt.span, "try", sugg, applicability);
112+
if let Some(ret_suggs) = ret_suggs {
113+
diag.multipart_suggestion("...and replace `return` with `continue`", ret_suggs, applicability);
117114
}
118-
)
115+
})
119116
}
120117
}
121118
}

tests/ui/needless_for_each_unfixable.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | } else {
2020
LL | println!("{}", v);
2121
LL | }
2222
...
23-
help: try replacing `return` with `continue`
23+
help: ...and replace `return` with `continue`
2424
|
2525
LL | continue;
2626
| ^^^^^^^^

0 commit comments

Comments
 (0)