Skip to content

Commit

Permalink
fix: simplify suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
wowinter13 committed Oct 15, 2024
1 parent 11162d1 commit 40cb24f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/unnecessary_filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a
},
expr.span,
format!("this `.{name}` can be written more simply"),
format!("try replacing with `.{sugg}`"),
format!("try instead"),
sugg.to_string(),
Applicability::MaybeIncorrect,
);
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/unnecessary_filter_map.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: this `.filter_map` can be written more simply
--> tests/ui/unnecessary_filter_map.rs:5:13
|
LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing with `.filter`: `filter`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `filter`
|
= note: `-D clippy::unnecessary-filter-map` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]`
Expand All @@ -18,7 +18,7 @@ LL | | return Some(x);
LL | | };
LL | | None
LL | | });
| |______^ help: try replacing with `.filter`: `filter`
| |______^ help: try instead: `filter`

error: this `.filter_map` can be written more simply
--> tests/ui/unnecessary_filter_map.rs:15:13
Expand All @@ -29,13 +29,13 @@ LL | |
LL | | 0 | 1 => None,
LL | | _ => Some(x),
LL | | });
| |______^ help: try replacing with `.filter`: `filter`
| |______^ help: try instead: `filter`

error: this `.filter_map` can be written more simply
--> tests/ui/unnecessary_filter_map.rs:21:13
|
LL | let _ = (0..4).filter_map(|x| Some(x + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing with `.map`: `map`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map`

error: redundant closure
--> tests/ui/unnecessary_filter_map.rs:28:57
Expand All @@ -56,13 +56,13 @@ error: this `.filter_map` can be written more simply
--> tests/ui/unnecessary_filter_map.rs:28:13
|
LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing with `.map`: `map`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map`

error: this `.filter_map` can be written more simply
--> tests/ui/unnecessary_filter_map.rs:165:14
|
LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing with `.filter`: `filter`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `filter`

error: aborting due to 8 previous errors

10 changes: 5 additions & 5 deletions tests/ui/unnecessary_find_map.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: this `.find_map` can be written more simply
--> tests/ui/unnecessary_find_map.rs:5:13
|
LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing with `.find`: `find`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `find`
|
= note: `-D clippy::unnecessary-find-map` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_find_map)]`
Expand All @@ -18,7 +18,7 @@ LL | | return Some(x);
LL | | };
LL | | None
LL | | });
| |______^ help: try replacing with `.find`: `find`
| |______^ help: try instead: `find`

error: this `.find_map` can be written more simply
--> tests/ui/unnecessary_find_map.rs:15:13
Expand All @@ -29,19 +29,19 @@ LL | |
LL | | 0 | 1 => None,
LL | | _ => Some(x),
LL | | });
| |______^ help: try replacing with `.find`: `find`
| |______^ help: try instead: `find`

error: this `.find_map` can be written more simply
--> tests/ui/unnecessary_find_map.rs:21:13
|
LL | let _ = (0..4).find_map(|x| Some(x + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing with `.map(..).next()`: `map(..).next()`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `map(..).next()`

error: this `.find_map` can be written more simply
--> tests/ui/unnecessary_find_map.rs:33:14
|
LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try replacing with `.find`: `find`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try instead: `find`

error: aborting due to 5 previous errors

0 comments on commit 40cb24f

Please sign in to comment.