Skip to content

Commit fbf13ce

Browse files
committed
Auto merge of #11866 - GuillaumeGomez:simplify-code-result_map_or_else_none, r=flip1995
Simplify code for `result_map_or_else_none` As mentioned in #11864. r? `@flip1995` changelog: Simplify code for `result_map_or_else_none`
2 parents 6cfbe57 + 148cd04 commit fbf13ce

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

clippy_lints/src/methods/result_map_or_else_none.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ pub(super) fn check<'tcx>(
1818
def_arg: &'tcx hir::Expr<'_>,
1919
map_arg: &'tcx hir::Expr<'_>,
2020
) {
21-
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
22-
23-
if !is_result {
24-
return;
25-
}
26-
27-
let f_arg_is_some = is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome);
28-
29-
if f_arg_is_some
21+
// lint if the caller of `map_or_else()` is a `Result`
22+
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result)
23+
// We check that it is mapped as `Some`.
24+
&& is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome)
3025
&& let hir::ExprKind::Closure(&hir::Closure { body, .. }) = def_arg.kind
3126
&& let body = cx.tcx.hir().body(body)
27+
// And finally we check that we return a `None` in the "else case".
3228
&& is_res_lang_ctor(cx, path_res(cx, peel_blocks(body.value)), OptionNone)
3329
{
3430
let msg = "called `map_or_else(|_| None, Some)` on a `Result` value";

0 commit comments

Comments
 (0)