@@ -8,6 +8,7 @@ mod get_unwrap;
8
8
mod implicit_clone;
9
9
mod inefficient_to_string;
10
10
mod inspect_for_each;
11
+ mod iter_cloned_collect;
11
12
mod iter_count;
12
13
mod manual_saturating_arithmetic;
13
14
mod ok_expect;
@@ -1711,7 +1712,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1711
1712
[ "nth" , ..] => lint_iter_nth_zero ( cx, expr, arg_lists[ 0 ] ) ,
1712
1713
[ "step_by" , ..] => lint_step_by ( cx, expr, arg_lists[ 0 ] ) ,
1713
1714
[ "next" , "skip" ] => lint_iter_skip_next ( cx, expr, arg_lists[ 1 ] ) ,
1714
- [ "collect" , "cloned" ] => lint_iter_cloned_collect ( cx, expr, arg_lists[ 1 ] ) ,
1715
+ [ "collect" , "cloned" ] => iter_cloned_collect :: check ( cx, expr, arg_lists[ 1 ] ) ,
1715
1716
[ "as_ref" ] => lint_asref ( cx, expr, "as_ref" , arg_lists[ 0 ] ) ,
1716
1717
[ "as_mut" ] => lint_asref ( cx, expr, "as_mut" , arg_lists[ 0 ] ) ,
1717
1718
[ "fold" , ..] => lint_unnecessary_fold ( cx, expr, arg_lists[ 0 ] , method_spans[ 0 ] ) ,
@@ -2494,27 +2495,6 @@ fn lint_extend(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>
2494
2495
}
2495
2496
}
2496
2497
2497
- fn lint_iter_cloned_collect < ' tcx > ( cx : & LateContext < ' tcx > , expr : & hir:: Expr < ' _ > , iter_args : & ' tcx [ hir:: Expr < ' _ > ] ) {
2498
- if_chain ! {
2499
- if is_type_diagnostic_item( cx, cx. typeck_results( ) . expr_ty( expr) , sym:: vec_type) ;
2500
- if let Some ( slice) = derefs_to_slice( cx, & iter_args[ 0 ] , cx. typeck_results( ) . expr_ty( & iter_args[ 0 ] ) ) ;
2501
- if let Some ( to_replace) = expr. span. trim_start( slice. span. source_callsite( ) ) ;
2502
-
2503
- then {
2504
- span_lint_and_sugg(
2505
- cx,
2506
- ITER_CLONED_COLLECT ,
2507
- to_replace,
2508
- "called `iter().cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \
2509
- more readable",
2510
- "try" ,
2511
- ".to_vec()" . to_string( ) ,
2512
- Applicability :: MachineApplicable ,
2513
- ) ;
2514
- }
2515
- }
2516
- }
2517
-
2518
2498
fn lint_unnecessary_fold ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , fold_args : & [ hir:: Expr < ' _ > ] , fold_span : Span ) {
2519
2499
fn check_fold_with_op (
2520
2500
cx : & LateContext < ' _ > ,
0 commit comments