Look for config in `.cargo/rustfmt.toml` and `.config/rustfmt.toml`
Feature Request
Summary
During the existing config search (walking up from the formatted file's directory), also check .cargo/rustfmt.toml and .config/rustfmt.toml in each directory, after the existing .rustfmt.toml / rustfmt.toml names. Existing layouts would keep working unchanged, since the current names would still take priority.
Motivation
Tool config in Rust repos is scattered across the repo root and two different dot-directories:
.cargo/config.toml # cargo
.cargo/mutants.toml # cargo-mutants (default location)
.cargo/deny.toml # cargo-deny (supported alongside deny.toml)
.config/nextest.toml # cargo-nextest (only location)
rustfmt.toml # rustfmt
clippy.toml # clippyI'm opening similar requests with clippy, nextest, cargo-mutants and cargo-deny, asking each to accept .cargo/<tool>.toml and .config/<tool>.toml so a project can keep all of it in one directory.
For rustfmt the only way to relocate the file today is --config-path, which doesn't really work in practice: editors and rust-analyzer invoke rustfmt directly, so every tool in the chain would need to be configured to pass it.
This is purely about config discovery and needs no knowledge of Cargo, since it's two extra file names checked during the directory walk rustfmt already does. So it should also work the same for cargo-less usage.
Separately: I'd also like rustfmt to read [workspace.metadata.rustfmt] / [package.metadata.rustfmt] from Cargo.toml. I know this was declined in #6296 (and discussed in #4074), so I'm only registering continued interest in case that position ever changes. The directory lookup above doesn't depend on it.
Related configuration options
None. This only affects where the config file is found, not formatting.
Source: rust-lang/rustfmt