Skip to content

Commit

Permalink
Tweak a suggestion message of needless_for_each
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Mar 31, 2021
1 parent bf1e3f7 commit e61f978
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions clippy_lints/src/needless_for_each.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
)
})
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/needless_for_each_unfixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL | } else {
LL | println!("{}", v);
LL | }
...
help: try replacing `return` with `continue`
help: ...and replace `return` with `continue`
|
LL | continue;
| ^^^^^^^^
Expand Down

0 comments on commit e61f978

Please sign in to comment.