RS.CLIPPY.UNINLINED_FORMAT_ARGS

Using non-inlined variables in `format!` calls

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: uninlined_format_args. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Detect when a variable is not inlined in a format string, and suggests to inline it.

Why is this bad?

Non-inlined code is slightly more difficult to read and understand, as it requires arguments to be matched against the format string. The inlined syntax, where allowed, is simpler.

Example

format!("{}", var);
format!("{v:?}", v = var);
format!("{0} {0}", var);
format!("{0:1$}", var, width);
format!("{:.*}", prec, var);

Use instead:

format!("{var}");
format!("{var:?}");
format!("{var} {var}");
format!("{var:width$}");
format!("{var:.prec$}");

If allow-mixed-uninlined-format-args is set to false in clippy.toml, the following code will also trigger the lint:

format!("{} {}", var, 1+2);

Use instead:

format!("{var} {}", 1+2);

Known Problems

If a format string contains a numbered argument that cannot be inlined nothing will be suggested, e.g. println!("{0}={1}", var, 1+2).

Configuration

  • allow-mixed-uninlined-format-args: Whether to allow mixed uninlined format args, e.g. format!("{} {}", a, foo.bar)

    (default: true)

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)