fix suggestion for search_is_some

This commit is contained in:
airt 2019-05-01 03:09:27 +08:00
parent bd0b75f6c3
commit c3fde34fd5

View file

@ -1977,10 +1977,16 @@ fn lint_search_is_some<'a, 'tcx>(
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
if_chain! {
if search_method == "find";
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node;
let closure_body = cx.tcx.hir().body(body_id);
if let hir::PatKind::Ref(..) = closure_body.arguments[0].pat.node;
then {
Some(search_snippet.replacen('&', "", 1))
} else {
None
}
};
// add note if not multi-line
span_note_and_lint(