fix suggestion for search_is_some naively

This commit is contained in:
airt 2019-05-01 01:08:16 +08:00
parent 2d4d275519
commit bd0b75f6c3

View file

@ -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,
@ -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 {