1
1
mod bind_instead_of_map;
2
2
mod bytes_nth;
3
+ mod clone_on_ref_ptr;
3
4
mod expect_used;
4
5
mod filetype_is_file;
5
6
mod filter_map_identity;
@@ -20,6 +21,7 @@ mod ok_expect;
20
21
mod option_as_ref_deref;
21
22
mod option_map_unwrap_or;
22
23
mod skip_while_next;
24
+ mod string_extend_chars;
23
25
mod suspicious_map;
24
26
mod uninit_assumed_init;
25
27
mod unnecessary_filter_map;
@@ -1707,7 +1709,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1707
1709
[ "is_some" , "rposition" ] => {
1708
1710
lint_search_is_some ( cx, expr, "rposition" , arg_lists[ 1 ] , arg_lists[ 0 ] , method_spans[ 1 ] )
1709
1711
} ,
1710
- [ "extend" , ..] => lint_extend ( cx, expr, arg_lists[ 0 ] ) ,
1712
+ [ "extend" , ..] => string_extend_chars :: check ( cx, expr, arg_lists[ 0 ] ) ,
1711
1713
[ "count" , "into_iter" ] => iter_count:: check ( cx, expr, & arg_lists[ 1 ] , "into_iter" ) ,
1712
1714
[ "count" , "iter" ] => iter_count:: check ( cx, expr, & arg_lists[ 1 ] , "iter" ) ,
1713
1715
[ "count" , "iter_mut" ] => iter_count:: check ( cx, expr, & arg_lists[ 1 ] , "iter_mut" ) ,
@@ -1767,7 +1769,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1767
1769
let self_ty = cx. typeck_results ( ) . expr_ty_adjusted ( & args[ 0 ] ) ;
1768
1770
if args. len ( ) == 1 && method_call. ident . name == sym:: clone {
1769
1771
lint_clone_on_copy ( cx, expr, & args[ 0 ] , self_ty) ;
1770
- lint_clone_on_ref_ptr ( cx, expr, & args[ 0 ] ) ;
1772
+ clone_on_ref_ptr :: check ( cx, expr, & args[ 0 ] ) ;
1771
1773
}
1772
1774
if args. len ( ) == 1 && method_call. ident . name == sym ! ( to_string) {
1773
1775
inefficient_to_string:: check ( cx, expr, & args[ 0 ] , self_ty) ;
@@ -2408,72 +2410,6 @@ fn lint_clone_on_copy(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Exp
2408
2410
}
2409
2411
}
2410
2412
2411
- fn lint_clone_on_ref_ptr ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , arg : & hir:: Expr < ' _ > ) {
2412
- let obj_ty = cx. typeck_results ( ) . expr_ty ( arg) . peel_refs ( ) ;
2413
-
2414
- if let ty:: Adt ( _, subst) = obj_ty. kind ( ) {
2415
- let caller_type = if is_type_diagnostic_item ( cx, obj_ty, sym:: Rc ) {
2416
- "Rc"
2417
- } else if is_type_diagnostic_item ( cx, obj_ty, sym:: Arc ) {
2418
- "Arc"
2419
- } else if match_type ( cx, obj_ty, & paths:: WEAK_RC ) || match_type ( cx, obj_ty, & paths:: WEAK_ARC ) {
2420
- "Weak"
2421
- } else {
2422
- return ;
2423
- } ;
2424
-
2425
- let snippet = snippet_with_macro_callsite ( cx, arg. span , ".." ) ;
2426
-
2427
- span_lint_and_sugg (
2428
- cx,
2429
- CLONE_ON_REF_PTR ,
2430
- expr. span ,
2431
- "using `.clone()` on a ref-counted pointer" ,
2432
- "try this" ,
2433
- format ! ( "{}::<{}>::clone(&{})" , caller_type, subst. type_at( 0 ) , snippet) ,
2434
- Applicability :: Unspecified , // Sometimes unnecessary ::<_> after Rc/Arc/Weak
2435
- ) ;
2436
- }
2437
- }
2438
-
2439
- fn lint_string_extend ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , args : & [ hir:: Expr < ' _ > ] ) {
2440
- let arg = & args[ 1 ] ;
2441
- if let Some ( arglists) = method_chain_args ( arg, & [ "chars" ] ) {
2442
- let target = & arglists[ 0 ] [ 0 ] ;
2443
- let self_ty = cx. typeck_results ( ) . expr_ty ( target) . peel_refs ( ) ;
2444
- let ref_str = if * self_ty. kind ( ) == ty:: Str {
2445
- ""
2446
- } else if is_type_diagnostic_item ( cx, self_ty, sym:: string_type) {
2447
- "&"
2448
- } else {
2449
- return ;
2450
- } ;
2451
-
2452
- let mut applicability = Applicability :: MachineApplicable ;
2453
- span_lint_and_sugg (
2454
- cx,
2455
- STRING_EXTEND_CHARS ,
2456
- expr. span ,
2457
- "calling `.extend(_.chars())`" ,
2458
- "try this" ,
2459
- format ! (
2460
- "{}.push_str({}{})" ,
2461
- snippet_with_applicability( cx, args[ 0 ] . span, ".." , & mut applicability) ,
2462
- ref_str,
2463
- snippet_with_applicability( cx, target. span, ".." , & mut applicability)
2464
- ) ,
2465
- applicability,
2466
- ) ;
2467
- }
2468
- }
2469
-
2470
- fn lint_extend ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , args : & [ hir:: Expr < ' _ > ] ) {
2471
- let obj_ty = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) . peel_refs ( ) ;
2472
- if is_type_diagnostic_item ( cx, obj_ty, sym:: string_type) {
2473
- lint_string_extend ( cx, expr, args) ;
2474
- }
2475
- }
2476
-
2477
2413
fn lint_unnecessary_fold ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , fold_args : & [ hir:: Expr < ' _ > ] , fold_span : Span ) {
2478
2414
fn check_fold_with_op (
2479
2415
cx : & LateContext < ' _ > ,
0 commit comments