Skip to content

Commit 261dd1c

Browse files
committed
Don't overlap with if_let_some_result
1 parent dab7a43 commit 261dd1c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

clippy_lints/src/option_if_let_else.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ declare_clippy_lint! {
7070

7171
declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]);
7272

73+
fn is_result_ok(cx: &LateContext<'_, '_>, expr: &'_ Expr<'_>) -> bool {
74+
if_chain! {
75+
if let ExprKind::MethodCall(ref path, _, &[ref receiver]) = &expr.kind;
76+
if path.ident.name.to_ident_string() == "ok";
77+
if match_type(cx, &cx.tables.expr_ty(&receiver), &paths::RESULT);
78+
then {
79+
true
80+
} else {
81+
false
82+
}
83+
}
84+
}
85+
7386
/// If this expression is the option if let/else construct we're detecting, then
7487
/// this function returns Some(Option<_> tested against, the method to call on
7588
/// the object (map_or or map_or_else), expression if Option is Some,
@@ -79,6 +92,7 @@ fn detect_option_if_let_else<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) -
7992
if let ExprKind::Match(let_body, arms, MatchSource::IfLetDesugar{contains_else_clause: true}) = &expr.kind;
8093
if arms.len() == 2;
8194
if match_type(cx, &cx.tables.expr_ty(let_body), &paths::OPTION);
95+
if !is_result_ok(cx, let_body);
8296
if let PatKind::TupleStruct(path, &[inner_pat], _) = &arms[0].pat.kind;
8397
if let PatKind::Binding(_, _, id, _) = &inner_pat.kind;
8498
then {

0 commit comments

Comments
 (0)