@@ -224,13 +224,11 @@ impl<'a, 'tcx> FormatArgsExpr<'a, 'tcx> {
224
224
if let FormatArgsPiece :: Placeholder ( placeholder) = piece
225
225
&& let Ok ( index) = placeholder. argument . index
226
226
&& let Some ( arg) = self . format_args . arguments . all_args ( ) . get ( index)
227
+ && let Some ( arg_expr) = find_format_arg_expr ( self . expr , arg)
227
228
{
228
- let arg_expr = find_format_arg_expr ( self . expr , arg) ;
229
-
230
229
self . check_unused_format_specifier ( placeholder, arg_expr) ;
231
230
232
- if let Ok ( arg_expr) = arg_expr
233
- && placeholder. format_trait == FormatTrait :: Display
231
+ if placeholder. format_trait == FormatTrait :: Display
234
232
&& placeholder. format_options == FormatOptions :: default ( )
235
233
&& !self . is_aliased ( index)
236
234
{
@@ -242,28 +240,13 @@ impl<'a, 'tcx> FormatArgsExpr<'a, 'tcx> {
242
240
}
243
241
}
244
242
245
- fn check_unused_format_specifier (
246
- & self ,
247
- placeholder : & FormatPlaceholder ,
248
- arg_expr : Result < & Expr < ' _ > , & rustc_ast:: Expr > ,
249
- ) {
250
- let ty_or_ast_expr = arg_expr. map ( |expr| self . cx . typeck_results ( ) . expr_ty ( expr) . peel_refs ( ) ) ;
251
-
252
- let is_format_args = match ty_or_ast_expr {
253
- Ok ( ty) => is_type_lang_item ( self . cx , ty, LangItem :: FormatArguments ) ,
254
- Err ( expr) => matches ! ( expr. peel_parens_and_refs( ) . kind, rustc_ast:: ExprKind :: FormatArgs ( _) ) ,
255
- } ;
256
-
243
+ fn check_unused_format_specifier ( & self , placeholder : & FormatPlaceholder , arg : & Expr < ' _ > ) {
257
244
let options = & placeholder. format_options ;
258
245
259
- let arg_span = match arg_expr {
260
- Ok ( expr) => expr. span ,
261
- Err ( expr) => expr. span ,
262
- } ;
263
-
264
246
if let Some ( placeholder_span) = placeholder. span
265
- && is_format_args
266
247
&& * options != FormatOptions :: default ( )
248
+ && let ty = self . cx . typeck_results ( ) . expr_ty ( arg) . peel_refs ( )
249
+ && is_type_lang_item ( self . cx , ty, LangItem :: FormatArguments )
267
250
{
268
251
span_lint_and_then (
269
252
self . cx ,
@@ -274,7 +257,7 @@ impl<'a, 'tcx> FormatArgsExpr<'a, 'tcx> {
274
257
let mut suggest_format = |spec| {
275
258
let message = format ! ( "for the {spec} to apply consider using `format!()`" ) ;
276
259
277
- if let Some ( mac_call) = matching_root_macro_call ( self . cx , arg_span , sym:: format_args_macro) {
260
+ if let Some ( mac_call) = matching_root_macro_call ( self . cx , arg . span , sym:: format_args_macro) {
278
261
diag. span_suggestion (
279
262
self . cx . sess ( ) . source_map ( ) . span_until_char ( mac_call. span , '!' ) ,
280
263
message,
0 commit comments