format code

This commit is contained in:
airt 2019-05-01 04:03:51 +08:00
parent c3fde34fd5
commit 5d6a100f81

View file

@ -1976,18 +1976,17 @@ fn lint_search_is_some<'a, 'tcx>(
let search_snippet = snippet(cx, search_args[1].span, ".."); let search_snippet = snippet(cx, search_args[1].span, "..");
if search_snippet.lines().count() <= 1 { if search_snippet.lines().count() <= 1 {
// suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()` // suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()`
let any_search_snippet = let any_search_snippet = if_chain! {
if_chain! { if search_method == "find";
if search_method == "find"; if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node;
if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node; let closure_body = cx.tcx.hir().body(body_id);
let closure_body = cx.tcx.hir().body(body_id); if let hir::PatKind::Ref(..) = closure_body.arguments[0].pat.node;
if let hir::PatKind::Ref(..) = closure_body.arguments[0].pat.node; then {
then { Some(search_snippet.replacen('&', "", 1))
Some(search_snippet.replacen('&', "", 1)) } else {
} else { None
None }
} };
};
// add note if not multi-line // add note if not multi-line
span_note_and_lint( span_note_and_lint(
cx, cx,
@ -1997,7 +1996,8 @@ fn lint_search_is_some<'a, 'tcx>(
expr.span, expr.span,
&format!( &format!(
"replace `{0}({1}).is_some()` with `any({2})`", "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) any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
), ),
); );