mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-24 13:43:04 +00:00
fix suggestion for search_is_some naively
This commit is contained in:
parent
2d4d275519
commit
bd0b75f6c3
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user