In workspaces, `cargo fmt` only works in the top-level directory #8724
Open
Nobody has claimed this yet.
C-bug
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Describe the bug
$ cargo fmt
Failed to find targets
cargo-fmt 1.4.18
This utility formats all bin and lib files of the current crate using rustfmt.
USAGE:
cargo fmt [FLAGS] [OPTIONS] [-- <rustfmt-options>...]
FLAGS:
--all Format all packages (only usable in workspaces)
-q, --quiet No output printed to stdout
-v, --verbose Use verbose output
--version Print rustfmt version and exit
OPTIONS:
--manifest-path <manifest-path> Specify path to Cargo.toml
--message-format <message-format> Specify message-format: short|json|human
-p, --package <package>... Specify package to format (only usable in workspaces)
ARGS:
<rustfmt-options>... Options passed to rustfmt
To Reproduce
cargo new outer && cd outercargo new innerprintf '[workspace]\nmembers = ["inner"]' >> Cargo.tomlcd srccargo fmt
Expected behavior
cargo fmt should format all packages in the workspace, like it does from the top-level directory.
Meta
- rustfmt version: rustfmt 1.4.21-nightly (01f2ead 2020-09-04), but the problem is also present on
rustfmt 1.4.18-stable (8157a3f 2020-07-15) - From where did you install rustfmt?: rustup
- How do you run rustfmt:
cargo fmt
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
Reproduce the issue with the listed cargo new, workspace, and cargo fmt commands, especially from the inner src directory. Trace how cargo fmt discovers the workspace and packages when invoked below the top level; done means cargo fmt from that directory formats all workspace packages as it does from the workspace root.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100