Skip to content

Clippy does not respect rules to allow uninlined_format_args #14694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rayokamoto opened this issue Apr 26, 2025 · 2 comments
Open

Clippy does not respect rules to allow uninlined_format_args #14694

rayokamoto opened this issue Apr 26, 2025 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@rayokamoto
Copy link

Summary

In Rust 1.88 Nightly, there are issues with cargo clippy where allowing uninlined_format_args does not work:

  • Setting allow-mixed-uninlined-format-args = true in clippy.toml does nothing, in both projects with a single package and Cargo workspaces
  • Setting the linting rule in Cargo.toml (with uninlined_format_args = "allow"), does work for a single crate ([lints.clippy]), but not when it's defined in the workspace Cargo.toml file ([workspace.lints.clippy])

I found #12161 but applying the suggestions here does not have any effect.

Everything I mentioned above works fine in Rust 1.86 (stable). These issues might have been caused as part of #14160.

Reproducer

With single crate

Make sure you are using Rust 1.88 Nightly. Create a new package with cargo init. In the src/main.rs file, add some code that will trigger the uninlined_format_args warning:

fn main() {
    let name = "Bob";
    println!("Hello, {}!", name);
}

Create a clippy.toml file and add the following:

allow-mixed-uninlined-format-args = true

Now try to run cargo clippy. The expectation is to have the Clippy checks pass with no warnings. However, the actual result is this:

warning: variables can be used directly in the `format!` string
 --> src/main.rs:3:5
  |
3 |     println!("Hello, {}!", name);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
  = note: `#[warn(clippy::uninlined_format_args)]` on by default
help: change this to
  |
3 -     println!("Hello, {}!", name);
3 +     println!("Hello, {name}!");
  |

warning: `rust-clippy` (bin "rust-clippy") generated 1 warning (run `cargo clippy --fix --bin "rust-clippy"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s

If you add the following to Cargo.toml, and then rerun cargo clippy, you will get the expected result.

[lints.clippy]
uninlined_format_args = "allow"

With workspaces

Create a Cargo workspace project (with Rust 1.88 Nightly). The root Cargo.toml should look something like this:

[workspace]
resolver = "2"
members = ["crates/*"]
default-members = ["crates/clippy-test"]

[workspace.package]
version = "0.1.0"
edition = "2024"

[workspace.dependencies]

[workspace.lints.clippy]
uninlined_format_args = "allow"

Then, create a new crate. The folder structure should be like so:

crates
└── clippy-test
    ├── Cargo.toml
    └── src
        └── main.rs

The crates/clippy-test/Cargo.toml file should look something like this:

[package]
name = "clippy-test"
version.workspace = true
edition.workspace = true

[[bin]]
name = "clippy-test"
path = "src/main.rs"

Then, main.rs can be the same as the single crate version:

fn main() {
    let name = "Bob";
    println!("Hello, {}!", name);
}

If you try to create a clippy.toml file with the same allow-mixed-uninlined-format-args = true setting, Clippy will not respect this and still emit the warnings.

Trying to set it in the workspace (root) Cargo.toml file does not work either. This is the config:

[workspace.lints.clippy]
uninlined_format_args = "allow"

However, if you put this in the clippy-test crate that we've created, the config option finally works and Clippy works as intended:

[lints.clippy]
uninlined_format_args = "allow"

Version

rustc 1.88.0-nightly (b4c8b0c3f 2025-04-25)
binary: rustc
commit-hash: b4c8b0c3f0533bb342a4873ff59bdad3883ab8e3
commit-date: 2025-04-25
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Additional Labels

No response

@rayokamoto rayokamoto added the C-bug Category: Clippy is not doing the correct thing label Apr 26, 2025
@Alexendoo
Copy link
Member

The configuration option would prevent linting cases like format!("{} {}", name some_struct.field) (it defaults to true). It doesn't disable the lint itself

For a project to inherit the workspace lints table you need to set lints.workspace = true in it

@rayokamoto
Copy link
Author

rayokamoto commented Apr 27, 2025

Ah thanks for that, setting lints.workspace = true seems to do the trick. clippy.toml doesn't work but I guess that there isn't feature parity with clippy.toml and Cargo.toml lint configs?

The configuration option would prevent linting cases like format!("{} {}", name some_struct.field)

That makes sense, as you wouldn't be able to do something like format!("{some_struct.field}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

2 participants