Revert "Exclude pattern guards from unnecessary_fold lint"

This reverts commit d3c06f7252.
This commit is contained in:
Joshua Holmer 2018-10-12 13:15:55 -04:00
parent d3c06f7252
commit 863c8e26fc
2 changed files with 0 additions and 25 deletions

View File

@ -9,7 +9,6 @@
use crate::rustc::hir;
use crate::rustc::hir::{ExprKind, Guard, Node};
use crate::rustc::hir::def::Def;
use crate::rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass};
use crate::rustc::ty::{self, Ty};
@ -1429,23 +1428,6 @@ fn check_fold_with_op(
return;
}
// `Iterator::any` cannot be used within a pattern guard
// See https://github.com/rust-lang-nursery/rust-clippy/issues/3069
if_chain! {
if let Some(fold_parent) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(expr.id));
if let Node::Expr(fold_parent) = fold_parent;
if let ExprKind::Match(_, ref arms, _) = fold_parent.node;
if arms.iter().any(|arm| {
if let Some(Guard::If(ref guard)) = arm.guard {
return guard.id == expr.id;
}
false
});
then {
return;
}
}
assert!(fold_args.len() == 3,
"Expected fold_args to have three entries - the receiver, the initial value and the closure");

View File

@ -45,13 +45,6 @@ fn unnecessary_fold_should_ignore() {
let _ = [(0..2), (0..3)].iter().fold(0, |a, b| a + b.len());
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
// Because `any` takes the iterator as a mutable reference,
// it cannot be used in a pattern guard, and we must use `fold`.
match 1 {
_ if (0..3).fold(false, |acc, x| acc || x > 2) => {}
_ => {}
}
}
fn main() {}