@@ -1309,7 +1309,7 @@ declare_clippy_lint! {
13091309
13101310declare_clippy_lint ! {
13111311 /// ### What it does
1312- /// Checks for `filter_map` calls which could be replaced by `filter` or `map`.
1312+ /// Checks for `filter_map` calls that could be replaced by `filter` or `map`.
13131313 /// More specifically it checks if the closure provided is only performing one of the
13141314 /// filter or map operations and suggests the appropriate option.
13151315 ///
@@ -1337,6 +1337,36 @@ declare_clippy_lint! {
13371337 "using `filter_map` when a more succinct alternative exists"
13381338}
13391339
1340+ declare_clippy_lint ! {
1341+ /// ### What it does
1342+ /// Checks for `find_map` calls that could be replaced by `find` or `map`. More
1343+ /// specifically it checks if the closure provided is only performing one of the
1344+ /// find or map operations and suggests the appropriate option.
1345+ ///
1346+ /// ### Why is this bad?
1347+ /// Complexity. The intent is also clearer if only a single
1348+ /// operation is being performed.
1349+ ///
1350+ /// ### Example
1351+ /// ```rust
1352+ /// let _ = (0..3).find_map(|x| if x > 2 { Some(x) } else { None });
1353+ ///
1354+ /// // As there is no transformation of the argument this could be written as:
1355+ /// let _ = (0..3).find(|&x| x > 2);
1356+ /// ```
1357+ ///
1358+ /// ```rust
1359+ /// let _ = (0..4).find_map(|x| Some(x + 1));
1360+ ///
1361+ /// // As there is no conditional check on the argument this could be written as:
1362+ /// let _ = (0..4).map(|x| x + 1).next();
1363+ /// ```
1364+ #[ clippy:: version = "1.61.0" ]
1365+ pub UNNECESSARY_FIND_MAP ,
1366+ complexity,
1367+ "using `find_map` when a more succinct alternative exists"
1368+ }
1369+
13401370declare_clippy_lint ! {
13411371 /// ### What it does
13421372 /// Checks for `into_iter` calls on references which should be replaced by `iter`
@@ -2020,6 +2050,7 @@ impl_lint_pass!(Methods => [
20202050 USELESS_ASREF ,
20212051 UNNECESSARY_FOLD ,
20222052 UNNECESSARY_FILTER_MAP ,
2053+ UNNECESSARY_FIND_MAP ,
20232054 INTO_ITER_ON_REF ,
20242055 SUSPICIOUS_MAP ,
20252056 UNINIT_ASSUMED_INIT ,
@@ -2305,9 +2336,12 @@ fn check_methods<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, msrv: Optio
23052336 extend_with_drain:: check ( cx, expr, recv, arg) ;
23062337 } ,
23072338 ( "filter_map" , [ arg] ) => {
2308- unnecessary_filter_map:: check ( cx, expr, arg) ;
2339+ unnecessary_filter_map:: check ( cx, expr, arg, name ) ;
23092340 filter_map_identity:: check ( cx, expr, arg, span) ;
23102341 } ,
2342+ ( "find_map" , [ arg] ) => {
2343+ unnecessary_filter_map:: check ( cx, expr, arg, name) ;
2344+ } ,
23112345 ( "flat_map" , [ arg] ) => {
23122346 flat_map_identity:: check ( cx, expr, arg, span) ;
23132347 flat_map_option:: check ( cx, expr, arg, span) ;
0 commit comments