diff options
| author | bors <bors@rust-lang.org> | 2023-11-25 11:24:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-25 11:24:17 +0000 |
| commit | fbf13cea16b98fd65487559fb2b82c6cf1207c73 (patch) | |
| tree | 36ecc35a57f53b36c030e9ff69209d5358e0b140 | |
| parent | 6cfbe5707546248487d09fc338598254f352edfc (diff) | |
| parent | 148cd041406e8c950a5bb9cc655113fbcff53f98 (diff) | |
| download | rust-fbf13cea16b98fd65487559fb2b82c6cf1207c73.tar.gz rust-fbf13cea16b98fd65487559fb2b82c6cf1207c73.zip | |
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 https://github.com/rust-lang/rust-clippy/pull/11864. r? `@flip1995` changelog: Simplify code for `result_map_or_else_none`
| -rw-r--r-- | clippy_lints/src/methods/result_map_or_else_none.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/clippy_lints/src/methods/result_map_or_else_none.rs b/clippy_lints/src/methods/result_map_or_else_none.rs index b0e3ca367b4..bc16a112816 100644 --- a/clippy_lints/src/methods/result_map_or_else_none.rs +++ b/clippy_lints/src/methods/result_map_or_else_none.rs @@ -18,17 +18,13 @@ pub(super) fn check<'tcx>( def_arg: &'tcx hir::Expr<'_>, map_arg: &'tcx hir::Expr<'_>, ) { - let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result); - - if !is_result { - return; - } - - let f_arg_is_some = is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome); - - if f_arg_is_some + // lint if the caller of `map_or_else()` is a `Result` + if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result) + // We check that it is mapped as `Some`. + && is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome) && let hir::ExprKind::Closure(&hir::Closure { body, .. }) = def_arg.kind && let body = cx.tcx.hir().body(body) + // And finally we check that we return a `None` in the "else case". && is_res_lang_ctor(cx, path_res(cx, peel_blocks(body.value)), OptionNone) { let msg = "called `map_or_else(|_| None, Some)` on a `Result` value"; |
