@@ -39,20 +39,20 @@ declare_lint_pass!(RepeatOnce => [REPEAT_ONCE]);
39
39
impl < ' tcx > LateLintPass < ' tcx > for RepeatOnce {
40
40
fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & ' tcx Expr < ' _ > ) {
41
41
if_chain ! {
42
- if let ExprKind :: MethodCall ( ref path, _, ref args , _) = expr. kind;
42
+ if let ExprKind :: MethodCall ( path, _, [ receiver , count ] , _) = & expr. kind;
43
43
if path. ident. name == sym!( repeat) ;
44
- if let Some ( Constant :: Int ( 1 ) ) = constant_context( cx, cx. typeck_results( ) ) . expr( & args [ 1 ] ) ;
45
- if !in_macro( args [ 0 ] . span) ;
44
+ if let Some ( Constant :: Int ( 1 ) ) = constant_context( cx, cx. typeck_results( ) ) . expr( & count ) ;
45
+ if !in_macro( receiver . span) ;
46
46
then {
47
- let ty = walk_ptrs_ty( cx. typeck_results( ) . expr_ty( & args [ 0 ] ) ) ;
47
+ let ty = walk_ptrs_ty( cx. typeck_results( ) . expr_ty( & receiver ) ) ;
48
48
if ty. is_str( ) {
49
49
span_lint_and_sugg(
50
50
cx,
51
51
REPEAT_ONCE ,
52
52
expr. span,
53
53
"calling `repeat(1)` on str" ,
54
54
"consider using `.to_string()` instead" ,
55
- format!( "{}.to_string()" , snippet( cx, args [ 0 ] . span, r#""...""# ) ) ,
55
+ format!( "{}.to_string()" , snippet( cx, receiver . span, r#""...""# ) ) ,
56
56
Applicability :: MachineApplicable ,
57
57
) ;
58
58
} else if ty. builtin_index( ) . is_some( ) {
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce {
62
62
expr. span,
63
63
"calling `repeat(1)` on slice" ,
64
64
"consider using `.to_vec()` instead" ,
65
- format!( "{}.to_vec()" , snippet( cx, args [ 0 ] . span, r#""...""# ) ) ,
65
+ format!( "{}.to_vec()" , snippet( cx, receiver . span, r#""...""# ) ) ,
66
66
Applicability :: MachineApplicable ,
67
67
) ;
68
68
} else if is_type_diagnostic_item( cx, ty, sym!( string_type) ) {
@@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce {
72
72
expr. span,
73
73
"calling `repeat(1)` on a string literal" ,
74
74
"consider using `.clone()` instead" ,
75
- format!( "{}.clone()" , snippet( cx, args [ 0 ] . span, r#""...""# ) ) ,
75
+ format!( "{}.clone()" , snippet( cx, receiver . span, r#""...""# ) ) ,
76
76
Applicability :: MachineApplicable ,
77
77
) ;
78
78
}
0 commit comments