diff --git a/clippy_lints/src/ok_if_let.rs b/clippy_lints/src/ok_if_let.rs index c2069d98e77..a0c11bbb4ab 100644 --- a/clippy_lints/src/ok_if_let.rs +++ b/clippy_lints/src/ok_if_let.rs @@ -38,11 +38,16 @@ impl LateLintPass for OkIfLetPass { let MatchSource::IfLetDesugar { .. } = *source, //test if it is an If Let let ExprMethodCall(_, _, ref result_types) = op.node, //check is expr.ok() has type Result.ok() let PatKind::TupleStruct(ref x, ref y, _) = body[0].pats[0].node, //get operation - let Some(some_expr_string) = snippet_opt(cx, y[0].span), let Some(_) = method_chain_args(op, &["ok"]) //test to see if using ok() methoduse std::marker::Sized; ], { let is_result_type = match_type(cx, cx.tcx.expr_ty(&result_types[0]), &paths::RESULT); + let mut some_expr_string = String::from(""); + if y.len() > 0 { + if let Some(x) = snippet_opt(cx, y[0].span) { + some_expr_string = x; + } + } if print::path_to_string(x) == "Some" && is_result_type { span_help_and_lint(cx, IF_LET_SOME_RESULT, expr.span, "Matching on `Some` with `ok()` is redundant",