@@ -39,20 +39,20 @@ declare_lint_pass!(RepeatOnce => [REPEAT_ONCE]);
3939impl < ' tcx > LateLintPass < ' tcx > for RepeatOnce {
4040 fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & ' tcx Expr < ' _ > ) {
4141 if_chain ! {
42- if let ExprKind :: MethodCall ( ref path, _, ref args , _) = expr. kind;
42+ if let ExprKind :: MethodCall ( path, _, [ receiver , count ] , _) = & expr. kind;
4343 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) ;
4646 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 ) ) ;
4848 if ty. is_str( ) {
4949 span_lint_and_sugg(
5050 cx,
5151 REPEAT_ONCE ,
5252 expr. span,
5353 "calling `repeat(1)` on str" ,
5454 "consider using `.to_string()` instead" ,
55- format!( "{}.to_string()" , snippet( cx, args [ 0 ] . span, r#""...""# ) ) ,
55+ format!( "{}.to_string()" , snippet( cx, receiver . span, r#""...""# ) ) ,
5656 Applicability :: MachineApplicable ,
5757 ) ;
5858 } else if ty. builtin_index( ) . is_some( ) {
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce {
6262 expr. span,
6363 "calling `repeat(1)` on slice" ,
6464 "consider using `.to_vec()` instead" ,
65- format!( "{}.to_vec()" , snippet( cx, args [ 0 ] . span, r#""...""# ) ) ,
65+ format!( "{}.to_vec()" , snippet( cx, receiver . span, r#""...""# ) ) ,
6666 Applicability :: MachineApplicable ,
6767 ) ;
6868 } else if is_type_diagnostic_item( cx, ty, sym!( string_type) ) {
@@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce {
7272 expr. span,
7373 "calling `repeat(1)` on a string literal" ,
7474 "consider using `.clone()` instead" ,
75- format!( "{}.clone()" , snippet( cx, args [ 0 ] . span, r#""...""# ) ) ,
75+ format!( "{}.clone()" , snippet( cx, receiver . span, r#""...""# ) ) ,
7676 Applicability :: MachineApplicable ,
7777 ) ;
7878 }
0 commit comments