@@ -1148,7 +1148,7 @@ fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Spa
1148
1148
1149
1149
/// Checks for the `EXPECT_FUN_CALL` lint.
1150
1150
fn lint_expect_fun_call ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr , method_span : Span , name : & str , args : & [ hir:: Expr ] ) {
1151
- fn extract_format_args ( arg : & hir:: Expr ) -> Option < & hir:: HirVec < hir:: Expr > > {
1151
+ fn extract_format_args ( arg : & hir:: Expr ) -> Option < ( & hir:: Expr , & hir:: Expr ) > {
1152
1152
let arg = match & arg. node {
1153
1153
hir:: ExprKind :: AddrOf ( _, expr) => expr,
1154
1154
hir:: ExprKind :: MethodCall ( method_name, _, args)
@@ -1161,8 +1161,8 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
1161
1161
1162
1162
if let hir:: ExprKind :: Call ( ref inner_fun, ref inner_args) = arg. node {
1163
1163
if is_expn_of ( inner_fun. span , "format" ) . is_some ( ) && inner_args. len ( ) == 1 {
1164
- if let hir:: ExprKind :: Call ( _, ref format_args) = inner_args[ 0 ] . node {
1165
- return Some ( format_args) ;
1164
+ if let hir:: ExprKind :: Call ( _, format_args) = & inner_args[ 0 ] . node {
1165
+ return Some ( ( & format_args[ 0 ] , & format_args [ 1 ] ) ) ;
1166
1166
}
1167
1167
}
1168
1168
}
@@ -1174,17 +1174,19 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
1174
1174
cx : & LateContext < ' _ , ' _ > ,
1175
1175
a : & hir:: Expr ,
1176
1176
applicability : & mut Applicability ,
1177
- ) -> String {
1177
+ ) -> Vec < String > {
1178
1178
if let hir:: ExprKind :: AddrOf ( _, ref format_arg) = a. node {
1179
1179
if let hir:: ExprKind :: Match ( ref format_arg_expr, _, _) = format_arg. node {
1180
1180
if let hir:: ExprKind :: Tup ( ref format_arg_expr_tup) = format_arg_expr. node {
1181
- return snippet_with_applicability ( cx, format_arg_expr_tup[ 0 ] . span , ".." , applicability)
1182
- . into_owned ( ) ;
1181
+ return format_arg_expr_tup
1182
+ . iter ( )
1183
+ . map ( |a| snippet_with_applicability ( cx, a. span , ".." , applicability) . into_owned ( ) )
1184
+ . collect ( ) ;
1183
1185
}
1184
1186
}
1185
1187
} ;
1186
1188
1187
- snippet ( cx , a . span , ".." ) . into_owned ( )
1189
+ unreachable ! ( )
1188
1190
}
1189
1191
1190
1192
fn check_general_case (
@@ -1233,14 +1235,11 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
1233
1235
} ;
1234
1236
let span_replace_word = method_span. with_hi ( span. hi ( ) ) ;
1235
1237
1236
- if let Some ( format_args ) = extract_format_args ( arg) {
1238
+ if let Some ( ( fmt_spec , fmt_args ) ) = extract_format_args ( arg) {
1237
1239
let mut applicability = Applicability :: MachineApplicable ;
1238
- let args_len = format_args. len ( ) ;
1239
- let args: Vec < String > = format_args
1240
- . into_iter ( )
1241
- . take ( args_len - 1 )
1242
- . map ( |a| generate_format_arg_snippet ( cx, a, & mut applicability) )
1243
- . collect ( ) ;
1240
+ let mut args = vec ! [ snippet( cx, fmt_spec. span, ".." ) . into_owned( ) ] ;
1241
+
1242
+ args. extend ( generate_format_arg_snippet ( cx, fmt_args, & mut applicability) ) ;
1244
1243
1245
1244
let sugg = args. join ( ", " ) ;
1246
1245
0 commit comments