Skip to content

Commit 214d499

Browse files
committed
Add multiline test
1 parent dbe2bb4 commit 214d499

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

tests/ui/unnecessary_fold.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ fn unnecessary_fold_should_ignore() {
4141
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
4242
}
4343

44+
/// Should lint only the line containing the fold
45+
fn unnecessary_fold_over_multiple_lines() {
46+
let _ = (0..3)
47+
.map(|x| x + 1)
48+
.filter(|x| x % 2 == 0)
49+
.any(|x| x > 2);
50+
}
51+
4452
fn main() {}

tests/ui/unnecessary_fold.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ fn unnecessary_fold_should_ignore() {
4141
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
4242
}
4343

44+
/// Should lint only the line containing the fold
45+
fn unnecessary_fold_over_multiple_lines() {
46+
let _ = (0..3)
47+
.map(|x| x + 1)
48+
.filter(|x| x % 2 == 0)
49+
.fold(false, |acc, x| acc || x > 2);
50+
}
51+
4452
fn main() {}

tests/ui/unnecessary_fold.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ error: this `.fold` can be written more succinctly using another method
3030
LL | let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
3232

33-
error: aborting due to 5 previous errors
33+
error: this `.fold` can be written more succinctly using another method
34+
--> $DIR/unnecessary_fold.rs:49:10
35+
|
36+
LL | .fold(false, |acc, x| acc || x > 2);
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)`
38+
39+
error: aborting due to 6 previous errors
3440

0 commit comments

Comments
 (0)