@@ -70,6 +70,19 @@ declare_clippy_lint! {
70
70
71
71
declare_lint_pass ! ( OptionIfLetElse => [ OPTION_IF_LET_ELSE ] ) ;
72
72
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
+
73
86
/// If this expression is the option if let/else construct we're detecting, then
74
87
/// this function returns Some(Option<_> tested against, the method to call on
75
88
/// 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<'_>) -
79
92
if let ExprKind :: Match ( let_body, arms, MatchSource :: IfLetDesugar { contains_else_clause: true } ) = & expr. kind;
80
93
if arms. len( ) == 2 ;
81
94
if match_type( cx, & cx. tables. expr_ty( let_body) , & paths:: OPTION ) ;
95
+ if !is_result_ok( cx, let_body) ;
82
96
if let PatKind :: TupleStruct ( path, & [ inner_pat] , _) = & arms[ 0 ] . pat. kind;
83
97
if let PatKind :: Binding ( _, _, id, _) = & inner_pat. kind;
84
98
then {
0 commit comments