- err.span_suggestion(
- unexpanded_fmt_span.shrink_to_lo(),
- "you might be missing a string literal to format with",
- format!("\"{}\", ", sugg_fmt),
- Applicability::MaybeIncorrect,
- );
+ if let ExprKind::Block(block, None) = &efmt.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Expr(expr) = &block.stmts[0].kind
+ && let ExprKind::Path(None, path) = &expr.kind
+ && path.is_potential_trivial_const_arg()
+ {
+ err.multipart_suggestion(
+ "quote your inlined format argument to use as string literal",
+ vec![
+ (unexpanded_fmt_span.shrink_to_hi(), "\"".to_string()),
+ (unexpanded_fmt_span.shrink_to_lo(), "\"".to_string()),
+ ],
+ Applicability::MaybeIncorrect,
+ );
+ } else {
+ let sugg_fmt = match args.explicit_args().len() {
+ 0 => "{}".to_string(),
+ _ => format!("{}{{}}", "{} ".repeat(args.explicit_args().len())),
+ };
+ err.span_suggestion(
+ unexpanded_fmt_span.shrink_to_lo(),
+ "you might be missing a string literal to format with",
+ format!("\"{sugg_fmt}\", "),
+ Applicability::MaybeIncorrect,
+ );
+ }