Skip to content

Commit 863c8e2

Browse files
author
Joshua Holmer
committed
Revert "Exclude pattern guards from unnecessary_fold lint"
This reverts commit d3c06f7.
1 parent d3c06f7 commit 863c8e2

File tree

2 files changed

+0
-25
lines changed

2 files changed

+0
-25
lines changed

clippy_lints/src/methods/mod.rs

-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
use crate::rustc::hir;
12-
use crate::rustc::hir::{ExprKind, Guard, Node};
1312
use crate::rustc::hir::def::Def;
1413
use crate::rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass};
1514
use crate::rustc::ty::{self, Ty};
@@ -1429,23 +1428,6 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
14291428
return;
14301429
}
14311430

1432-
// `Iterator::any` cannot be used within a pattern guard
1433-
// See https://github.com/rust-lang-nursery/rust-clippy/issues/3069
1434-
if_chain! {
1435-
if let Some(fold_parent) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(expr.id));
1436-
if let Node::Expr(fold_parent) = fold_parent;
1437-
if let ExprKind::Match(_, ref arms, _) = fold_parent.node;
1438-
if arms.iter().any(|arm| {
1439-
if let Some(Guard::If(ref guard)) = arm.guard {
1440-
return guard.id == expr.id;
1441-
}
1442-
false
1443-
});
1444-
then {
1445-
return;
1446-
}
1447-
}
1448-
14491431
assert!(fold_args.len() == 3,
14501432
"Expected fold_args to have three entries - the receiver, the initial value and the closure");
14511433

tests/ui/unnecessary_fold.rs

-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ fn unnecessary_fold_should_ignore() {
4545

4646
let _ = [(0..2), (0..3)].iter().fold(0, |a, b| a + b.len());
4747
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
48-
49-
// Because `any` takes the iterator as a mutable reference,
50-
// it cannot be used in a pattern guard, and we must use `fold`.
51-
match 1 {
52-
_ if (0..3).fold(false, |acc, x| acc || x > 2) => {}
53-
_ => {}
54-
}
5548
}
5649

5750
fn main() {}

0 commit comments

Comments
 (0)