Skip to content

Commit

Permalink
fix suggestion for search_is_some naively
Browse files Browse the repository at this point in the history
  • Loading branch information
airt committed Apr 30, 2019
1 parent 2d4d275 commit bd0b75f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions clippy_lints/src/methods/mod.rs
Expand Up @@ -1975,6 +1975,13 @@ fn lint_search_is_some<'a, 'tcx>(
);
let search_snippet = snippet(cx, search_args[1].span, "..");
if search_snippet.lines().count() <= 1 {
// suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()`
let any_search_snippet =
if search_method == "find" && search_snippet.starts_with("|&") {
Some(search_snippet.replacen('&', "", 1))
} else {
None
};
// add note if not multi-line
span_note_and_lint(
cx,
Expand All @@ -1983,8 +1990,9 @@ fn lint_search_is_some<'a, 'tcx>(
&msg,
expr.span,
&format!(
"replace `{0}({1}).is_some()` with `any({1})`",
search_method, search_snippet
"replace `{0}({1}).is_some()` with `any({2})`",
search_method, search_snippet,
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
),
);
} else {
Expand Down

0 comments on commit bd0b75f

Please sign in to comment.