Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
airt committed Apr 30, 2019
1 parent c3fde34 commit 5d6a100
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions clippy_lints/src/methods/mod.rs
Expand Up @@ -1976,18 +1976,17 @@ 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_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
}
};
let any_search_snippet = 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(
cx,
Expand All @@ -1997,7 +1996,8 @@ fn lint_search_is_some<'a, 'tcx>(
expr.span,
&format!(
"replace `{0}({1}).is_some()` with `any({2})`",
search_method, search_snippet,
search_method,
search_snippet,
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
),
);
Expand Down

0 comments on commit 5d6a100

Please sign in to comment.