Fix FP with WHILE_LET_ON_ITERATOR and refutable pats

This commit is contained in:
mcarton
2016-09-16 15:45:44 +02:00
parent 90c390ec2a
commit c8986b4676
3 changed files with 68 additions and 3 deletions

View File

@@ -14,9 +14,9 @@ use std::collections::HashMap;
use syntax::ast;
use utils::sugg;
use utils::{snippet, span_lint, get_parent_expr, match_trait_method, match_type, multispan_sugg, in_external_macro,
span_help_and_lint, is_integer_literal, get_enclosing_block, span_lint_and_then, higher,
walk_ptrs_ty};
use utils::{snippet, span_lint, get_parent_expr, match_trait_method, match_type, multispan_sugg,
in_external_macro, is_refutable, span_help_and_lint, is_integer_literal,
get_enclosing_block, span_lint_and_then, higher, walk_ptrs_ty};
use utils::paths;
/// **What it does:** Checks for looping over the range of `0..len` of some
@@ -354,6 +354,7 @@ impl LateLintPass for Pass {
if method_name.node.as_str() == "next" &&
match_trait_method(cx, match_expr, &paths::ITERATOR) &&
lhs_constructor.name.as_str() == "Some" &&
!is_refutable(cx, &pat_args[0]) &&
!is_iterator_used_after_while_let(cx, iter_expr) {
let iterator = snippet(cx, method_args[0].span, "_");
let loop_var = snippet(cx, pat_args[0].span, "_");