Look for config in `.cargo/rustfmt.toml` and `.config/rustfmt.toml`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
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 # clippy
I'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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at rustfmt's existing configuration search that walks upward from the formatted file's directory, then inspect its config-discovery tests. Add .cargo/rustfmt.toml and .config/rustfmt.toml after .rustfmt.toml and rustfmt.toml at each directory, preserving the current names' priority; done means the new locations are found without changing existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100