Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit be6a103

Browse files
committed
add more tests to unnecessary_find_map and unnecessary_filter_map
1 parent 008746c commit be6a103

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

tests/ui/unnecessary_filter_map.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,9 @@ mod comment_1052978898 {
148148
})
149149
}
150150
}
151+
152+
fn issue11260() {
153+
// #11260 is about unnecessary_find_map, but the fix also kind of applies to
154+
// unnecessary_filter_map
155+
let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n));
156+
}

tests/ui/unnecessary_filter_map.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@ error: this `.filter_map` can be written more simply using `.map`
3434
LL | let _ = (0..4).filter_map(|x| Some(x + 1));
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

37-
error: aborting due to 4 previous errors
37+
error: this `.filter_map` can be written more simply using `.filter`
38+
--> $DIR/unnecessary_filter_map.rs:155:14
39+
|
40+
LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n));
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
43+
error: aborting due to 5 previous errors
3844

tests/ui/unnecessary_find_map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ fn find_map_none_changes_item_type() -> Option<bool> {
2323
}
2424

2525
fn issue11260() {
26+
let y = Some(1);
2627
let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
28+
let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(y)); // different option, so can't be just `.find()`
2729
}

tests/ui/unnecessary_find_map.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ LL | let _ = (0..4).find_map(|x| Some(x + 1));
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

3737
error: this `.find_map` can be written more simply using `.find`
38-
--> $DIR/unnecessary_find_map.rs:26:14
38+
--> $DIR/unnecessary_find_map.rs:27:14
3939
|
4040
LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)