Skip to content

Commit c3fde34

Browse files
committed
fix suggestion for search_is_some
1 parent bd0b75f commit c3fde34

File tree

1 file changed

+10
-4
lines changed
  • clippy_lints/src/methods

1 file changed

+10
-4
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,10 +1977,16 @@ fn lint_search_is_some<'a, 'tcx>(
19771977
if search_snippet.lines().count() <= 1 {
19781978
// suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()`
19791979
let any_search_snippet =
1980-
if search_method == "find" && search_snippet.starts_with("|&") {
1981-
Some(search_snippet.replacen('&', "", 1))
1982-
} else {
1983-
None
1980+
if_chain! {
1981+
if search_method == "find";
1982+
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node;
1983+
let closure_body = cx.tcx.hir().body(body_id);
1984+
if let hir::PatKind::Ref(..) = closure_body.arguments[0].pat.node;
1985+
then {
1986+
Some(search_snippet.replacen('&', "", 1))
1987+
} else {
1988+
None
1989+
}
19841990
};
19851991
// add note if not multi-line
19861992
span_note_and_lint(

0 commit comments

Comments
 (0)