Skip to content

Commit 4130dfb

Browse files
committed
Refactor 'lint_or_fun_call'
1 parent 419c87f commit 4130dfb

File tree

1 file changed

+26
-35
lines changed
  • clippy_lints/src/methods

1 file changed

+26
-35
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,46 +1281,37 @@ fn lint_or_fun_call<'a, 'tcx>(
12811281
(&paths::RESULT, true, &["or", "unwrap_or"], "else"),
12821282
];
12831283

1284-
// early check if the name is one we care about
1285-
if know_types.iter().all(|k| !k.2.contains(&name)) {
1286-
return;
1287-
}
1284+
if_chain! {
1285+
if know_types.iter().any(|k| k.2.contains(&name));
12881286

1289-
let mut finder = FunCallFinder { cx: &cx, found: false };
1290-
finder.visit_expr(&arg);
1291-
if !finder.found {
1292-
return;
1293-
}
1287+
let mut finder = FunCallFinder { cx: &cx, found: false };
1288+
if { finder.visit_expr(&arg); finder.found };
12941289

1295-
let self_ty = cx.tables.expr_ty(self_expr);
1290+
let self_ty = cx.tables.expr_ty(self_expr);
12961291

1297-
let (fn_has_arguments, poss, suffix) = if let Some(&(_, fn_has_arguments, poss, suffix)) =
1298-
know_types.iter().find(|&&i| match_type(cx, self_ty, i.0))
1299-
{
1300-
(fn_has_arguments, poss, suffix)
1301-
} else {
1302-
return;
1303-
};
1292+
if let Some(&(_, fn_has_arguments, poss, suffix)) =
1293+
know_types.iter().find(|&&i| match_type(cx, self_ty, i.0));
13041294

1305-
if !poss.contains(&name) {
1306-
return;
1307-
}
1295+
if poss.contains(&name);
13081296

1309-
let sugg: Cow<'_, _> = match (fn_has_arguments, !or_has_args) {
1310-
(true, _) => format!("|_| {}", snippet_with_macro_callsite(cx, arg.span, "..")).into(),
1311-
(false, false) => format!("|| {}", snippet_with_macro_callsite(cx, arg.span, "..")).into(),
1312-
(false, true) => snippet_with_macro_callsite(cx, fun_span, ".."),
1313-
};
1314-
let span_replace_word = method_span.with_hi(span.hi());
1315-
span_lint_and_sugg(
1316-
cx,
1317-
OR_FUN_CALL,
1318-
span_replace_word,
1319-
&format!("use of `{}` followed by a function call", name),
1320-
"try this",
1321-
format!("{}_{}({})", name, suffix, sugg),
1322-
Applicability::HasPlaceholders,
1323-
);
1297+
then {
1298+
let sugg: Cow<'_, _> = match (fn_has_arguments, !or_has_args) {
1299+
(true, _) => format!("|_| {}", snippet_with_macro_callsite(cx, arg.span, "..")).into(),
1300+
(false, false) => format!("|| {}", snippet_with_macro_callsite(cx, arg.span, "..")).into(),
1301+
(false, true) => snippet_with_macro_callsite(cx, fun_span, ".."),
1302+
};
1303+
let span_replace_word = method_span.with_hi(span.hi());
1304+
span_lint_and_sugg(
1305+
cx,
1306+
OR_FUN_CALL,
1307+
span_replace_word,
1308+
&format!("use of `{}` followed by a function call", name),
1309+
"try this",
1310+
format!("{}_{}({})", name, suffix, sugg),
1311+
Applicability::HasPlaceholders,
1312+
);
1313+
}
1314+
}
13241315
}
13251316

13261317
if args.len() == 2 {

0 commit comments

Comments
 (0)