@@ -11,6 +11,7 @@ mod inspect_for_each;
11
11
mod iter_cloned_collect;
12
12
mod iter_count;
13
13
mod manual_saturating_arithmetic;
14
+ mod map_collect_result_unit;
14
15
mod ok_expect;
15
16
mod option_as_ref_deref;
16
17
mod option_map_unwrap_or;
@@ -1739,7 +1740,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1739
1740
[ "unwrap_or_else" , ..] => unnecessary_lazy_eval:: check ( cx, expr, arg_lists[ 0 ] , "unwrap_or" ) ,
1740
1741
[ "get_or_insert_with" , ..] => unnecessary_lazy_eval:: check ( cx, expr, arg_lists[ 0 ] , "get_or_insert" ) ,
1741
1742
[ "ok_or_else" , ..] => unnecessary_lazy_eval:: check ( cx, expr, arg_lists[ 0 ] , "ok_or" ) ,
1742
- [ "collect" , "map" ] => lint_map_collect ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1743
+ [ "collect" , "map" ] => map_collect_result_unit :: check ( cx, expr, arg_lists[ 1 ] , arg_lists[ 0 ] ) ,
1743
1744
[ "for_each" , "inspect" ] => inspect_for_each:: check ( cx, expr, method_spans[ 1 ] ) ,
1744
1745
[ "to_owned" , ..] => implicit_clone:: check ( cx, expr, sym:: ToOwned ) ,
1745
1746
[ "to_os_string" , ..] => implicit_clone:: check ( cx, expr, sym:: OsStr ) ,
@@ -3530,42 +3531,6 @@ fn lint_into_iter(cx: &LateContext<'_>, expr: &hir::Expr<'_>, self_ref_ty: Ty<'_
3530
3531
}
3531
3532
}
3532
3533
3533
- fn lint_map_collect (
3534
- cx : & LateContext < ' _ > ,
3535
- expr : & hir:: Expr < ' _ > ,
3536
- map_args : & [ hir:: Expr < ' _ > ] ,
3537
- collect_args : & [ hir:: Expr < ' _ > ] ,
3538
- ) {
3539
- if_chain ! {
3540
- // called on Iterator
3541
- if let [ map_expr] = collect_args;
3542
- if match_trait_method( cx, map_expr, & paths:: ITERATOR ) ;
3543
- // return of collect `Result<(),_>`
3544
- let collect_ret_ty = cx. typeck_results( ) . expr_ty( expr) ;
3545
- if is_type_diagnostic_item( cx, collect_ret_ty, sym:: result_type) ;
3546
- if let ty:: Adt ( _, substs) = collect_ret_ty. kind( ) ;
3547
- if let Some ( result_t) = substs. types( ) . next( ) ;
3548
- if result_t. is_unit( ) ;
3549
- // get parts for snippet
3550
- if let [ iter, map_fn] = map_args;
3551
- then {
3552
- span_lint_and_sugg(
3553
- cx,
3554
- MAP_COLLECT_RESULT_UNIT ,
3555
- expr. span,
3556
- "`.map().collect()` can be replaced with `.try_for_each()`" ,
3557
- "try this" ,
3558
- format!(
3559
- "{}.try_for_each({})" ,
3560
- snippet( cx, iter. span, ".." ) ,
3561
- snippet( cx, map_fn. span, ".." )
3562
- ) ,
3563
- Applicability :: MachineApplicable ,
3564
- ) ;
3565
- }
3566
- }
3567
- }
3568
-
3569
3534
enum Convention {
3570
3535
Eq ( & ' static str ) ,
3571
3536
StartsWith ( & ' static str ) ,
0 commit comments