unnecessary_{find,filter}_map: make diagnostic spans more precise (#15929)
changelog: [`unnecessary_find_map`]: make diagnostic spans more precise changelog: [`unnecessary_filter_map`]: make diagnostic spans more precise
This commit is contained in:
commit
ca168c07a6
5 changed files with 83 additions and 63 deletions
|
|
@ -1,17 +1,17 @@
|
|||
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
|
||||
--> tests/ui/unnecessary_filter_map.rs:4:13
|
||||
--> tests/ui/unnecessary_filter_map.rs:4:20
|
||||
|
|
||||
LL | let _ = (0..4).filter_map(|x| if x > 1 { Some(x) } else { None });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::unnecessary-filter-map` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_filter_map)]`
|
||||
|
||||
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
|
||||
--> tests/ui/unnecessary_filter_map.rs:7:13
|
||||
--> tests/ui/unnecessary_filter_map.rs:7:20
|
||||
|
|
||||
LL | let _ = (0..4).filter_map(|x| {
|
||||
| _____________^
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | if x > 1 {
|
||||
|
|
@ -21,10 +21,10 @@ LL | | });
|
|||
| |______^
|
||||
|
||||
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
|
||||
--> tests/ui/unnecessary_filter_map.rs:15:13
|
||||
--> tests/ui/unnecessary_filter_map.rs:15:20
|
||||
|
|
||||
LL | let _ = (0..4).filter_map(|x| match x {
|
||||
| _____________^
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | | 0 | 1 => None,
|
||||
LL | | _ => Some(x),
|
||||
|
|
@ -32,22 +32,22 @@ LL | | });
|
|||
| |______^
|
||||
|
||||
error: this `.filter_map(..)` can be written more simply using `.map(..)`
|
||||
--> tests/ui/unnecessary_filter_map.rs:21:13
|
||||
--> tests/ui/unnecessary_filter_map.rs:21:20
|
||||
|
|
||||
LL | let _ = (0..4).filter_map(|x| Some(x + 1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this call to `.filter_map(..)` is unnecessary
|
||||
--> tests/ui/unnecessary_filter_map.rs:28:61
|
||||
--> tests/ui/unnecessary_filter_map.rs:28:46
|
||||
|
|
||||
LL | let _ = vec![Some(10), None].into_iter().filter_map(|x| Some(x));
|
||||
| ^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this `.filter_map(..)` can be written more simply using `.filter(..)`
|
||||
--> tests/ui/unnecessary_filter_map.rs:166:14
|
||||
--> tests/ui/unnecessary_filter_map.rs:166:33
|
||||
|
|
||||
LL | let _x = std::iter::once(1).filter_map(|n| (n > 1).then_some(n));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
fn main() {
|
||||
let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None });
|
||||
//~^ unnecessary_find_map
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
error: this `.find_map(..)` can be written more simply using `.find(..)`
|
||||
--> tests/ui/unnecessary_find_map.rs:4:13
|
||||
--> tests/ui/unnecessary_find_map.rs:2:20
|
||||
|
|
||||
LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::unnecessary-find-map` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_find_map)]`
|
||||
|
||||
error: this `.find_map(..)` can be written more simply using `.find(..)`
|
||||
--> tests/ui/unnecessary_find_map.rs:7:13
|
||||
--> tests/ui/unnecessary_find_map.rs:5:20
|
||||
|
|
||||
LL | let _ = (0..4).find_map(|x| {
|
||||
| _____________^
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | if x > 1 {
|
||||
|
|
@ -21,10 +21,10 @@ LL | | });
|
|||
| |______^
|
||||
|
||||
error: this `.find_map(..)` can be written more simply using `.find(..)`
|
||||
--> tests/ui/unnecessary_find_map.rs:15:13
|
||||
--> tests/ui/unnecessary_find_map.rs:13:20
|
||||
|
|
||||
LL | let _ = (0..4).find_map(|x| match x {
|
||||
| _____________^
|
||||
| ____________________^
|
||||
LL | |
|
||||
LL | | 0 | 1 => None,
|
||||
LL | | _ => Some(x),
|
||||
|
|
@ -32,16 +32,16 @@ LL | | });
|
|||
| |______^
|
||||
|
||||
error: this `.find_map(..)` can be written more simply using `.map(..).next()`
|
||||
--> tests/ui/unnecessary_find_map.rs:21:13
|
||||
--> tests/ui/unnecessary_find_map.rs:19:20
|
||||
|
|
||||
LL | let _ = (0..4).find_map(|x| Some(x + 1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this `.find_map(..)` can be written more simply using `.find(..)`
|
||||
--> tests/ui/unnecessary_find_map.rs:33:14
|
||||
--> tests/ui/unnecessary_find_map.rs:31:33
|
||||
|
|
||||
LL | let _x = std::iter::once(1).find_map(|n| (n > 1).then_some(n));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue