Only inline {} string literals in format_args.

Placeholders like {:123} would incorrectly get inlined.
This commit is contained in:
Mara Bos 2023-01-13 18:59:21 +01:00
parent caa6ba9e86
commit b7678d48b8

View File

@ -124,6 +124,7 @@ fn inline_literals(mut fmt: Cow<'_, FormatArgs>) -> Cow<'_, FormatArgs> {
let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i] else { continue }; let FormatArgsPiece::Placeholder(placeholder) = &fmt.template[i] else { continue };
let Ok(arg_index) = placeholder.argument.index else { continue }; let Ok(arg_index) = placeholder.argument.index else { continue };
if let FormatTrait::Display = placeholder.format_trait if let FormatTrait::Display = placeholder.format_trait
&& placeholder.format_options == Default::default()
&& let arg = fmt.arguments.all_args()[arg_index].expr.peel_parens_and_refs() && let arg = fmt.arguments.all_args()[arg_index].expr.peel_parens_and_refs()
&& let ExprKind::Lit(lit) = arg.kind && let ExprKind::Lit(lit) = arg.kind
&& let token::LitKind::Str | token::LitKind::StrRaw(_) = lit.kind && let token::LitKind::Str | token::LitKind::StrRaw(_) = lit.kind