@@ -10,6 +10,7 @@ mod filter_map_identity;
10
10
mod filter_map_map;
11
11
mod filter_map_next;
12
12
mod filter_next;
13
+ mod flat_map_identity;
13
14
mod from_iter_instead_of_collect;
14
15
mod get_unwrap;
15
16
mod implicit_clone;
@@ -1709,7 +1710,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1709
1710
[ "map" , "find" ] => filter_map:: check ( cx, expr, true ) ,
1710
1711
[ "flat_map" , "filter" ] => filter_flat_map:: check ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1711
1712
[ "flat_map" , "filter_map" ] => filter_map_flat_map:: check ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1712
- [ "flat_map" , ..] => lint_flat_map_identity ( cx, expr, arg_lists[ 0 ] , method_spans[ 0 ] ) ,
1713
+ [ "flat_map" , ..] => flat_map_identity :: check ( cx, expr, arg_lists[ 0 ] , method_spans[ 0 ] ) ,
1713
1714
[ "flatten" , "map" ] => lint_map_flatten ( cx, expr, arg_lists[ 1 ] ) ,
1714
1715
[ "is_some" , "find" ] => lint_search_is_some ( cx, expr, "find" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] ) ,
1715
1716
[ "is_some" , "position" ] => {
@@ -2755,55 +2756,6 @@ fn lint_map_or_none<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, map
2755
2756
) ;
2756
2757
}
2757
2758
2758
- /// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient
2759
- fn lint_flat_map_identity < ' tcx > (
2760
- cx : & LateContext < ' tcx > ,
2761
- expr : & ' tcx hir:: Expr < ' _ > ,
2762
- flat_map_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2763
- flat_map_span : Span ,
2764
- ) {
2765
- if match_trait_method ( cx, expr, & paths:: ITERATOR ) {
2766
- let arg_node = & flat_map_args[ 1 ] . kind ;
2767
-
2768
- let apply_lint = |message : & str | {
2769
- span_lint_and_sugg (
2770
- cx,
2771
- FLAT_MAP_IDENTITY ,
2772
- flat_map_span. with_hi ( expr. span . hi ( ) ) ,
2773
- message,
2774
- "try" ,
2775
- "flatten()" . to_string ( ) ,
2776
- Applicability :: MachineApplicable ,
2777
- ) ;
2778
- } ;
2779
-
2780
- if_chain ! {
2781
- if let hir:: ExprKind :: Closure ( _, _, body_id, _, _) = arg_node;
2782
- let body = cx. tcx. hir( ) . body( * body_id) ;
2783
-
2784
- if let hir:: PatKind :: Binding ( _, _, binding_ident, _) = body. params[ 0 ] . pat. kind;
2785
- if let hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( _, ref path) ) = body. value. kind;
2786
-
2787
- if path. segments. len( ) == 1 ;
2788
- if path. segments[ 0 ] . ident. name == binding_ident. name;
2789
-
2790
- then {
2791
- apply_lint( "called `flat_map(|x| x)` on an `Iterator`" ) ;
2792
- }
2793
- }
2794
-
2795
- if_chain ! {
2796
- if let hir:: ExprKind :: Path ( ref qpath) = arg_node;
2797
-
2798
- if match_qpath( qpath, & paths:: STD_CONVERT_IDENTITY ) ;
2799
-
2800
- then {
2801
- apply_lint( "called `flat_map(std::convert::identity)` on an `Iterator`" ) ;
2802
- }
2803
- }
2804
- }
2805
- }
2806
-
2807
2759
/// lint searching an Iterator followed by `is_some()`
2808
2760
/// or calling `find()` on a string followed by `is_some()`
2809
2761
fn lint_search_is_some < ' tcx > (
0 commit comments