From bd0b75f6c3a8c147aa95a64877280abf1fc1b069 Mon Sep 17 00:00:00 2001 From: airt Date: Wed, 1 May 2019 01:08:16 +0800 Subject: [PATCH] fix suggestion for search_is_some naively --- clippy_lints/src/methods/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index d8595ea9004..0b3a406bd76 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -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 {