mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-26 22:50:56 +00:00
Add multiline test
This commit is contained in:
parent
dbe2bb4256
commit
214d499103
3 changed files with 23 additions and 1 deletions
|
@ -41,4 +41,12 @@ fn unnecessary_fold_should_ignore() {
|
||||||
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
|
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Should lint only the line containing the fold
|
||||||
|
fn unnecessary_fold_over_multiple_lines() {
|
||||||
|
let _ = (0..3)
|
||||||
|
.map(|x| x + 1)
|
||||||
|
.filter(|x| x % 2 == 0)
|
||||||
|
.any(|x| x > 2);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -41,4 +41,12 @@ fn unnecessary_fold_should_ignore() {
|
||||||
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
|
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Should lint only the line containing the fold
|
||||||
|
fn unnecessary_fold_over_multiple_lines() {
|
||||||
|
let _ = (0..3)
|
||||||
|
.map(|x| x + 1)
|
||||||
|
.filter(|x| x % 2 == 0)
|
||||||
|
.fold(false, |acc, x| acc || x > 2);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -30,5 +30,11 @@ error: this `.fold` can be written more succinctly using another method
|
||||||
LL | let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
|
LL | let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: this `.fold` can be written more succinctly using another method
|
||||||
|
--> $DIR/unnecessary_fold.rs:49:10
|
||||||
|
|
|
||||||
|
LL | .fold(false, |acc, x| acc || x > 2);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)`
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue