]> git.lizzy.rs Git - rust.git/commitdiff
fixed array bounds checking
authorKit Freddura <kitfreddura@gmail.com>
Sun, 2 Oct 2016 21:26:41 +0000 (14:26 -0700)
committerKit Freddura <kitfreddura@gmail.com>
Sun, 2 Oct 2016 21:26:41 +0000 (14:26 -0700)
clippy_lints/src/ok_if_let.rs

index c2069d98e770bcfb361d38d2245fcc62f3212360..a0c11bbb4ab0f7a30181cea898812360ba4b15d5 100644 (file)
@@ -38,11 +38,16 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
             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<T,E>.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",