Skip to content

In workspaces, cargo fmt only works in the top-level directory #8724

New issue

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

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

Already on GitHub? # to your account

Closed
jyn514 opened this issue Sep 22, 2020 · 2 comments
Closed

In workspaces, cargo fmt only works in the top-level directory #8724

jyn514 opened this issue Sep 22, 2020 · 2 comments
Labels
C-bug Category: bug

Comments

@jyn514
Copy link
Member

jyn514 commented Sep 22, 2020

Problem

$ 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

Steps

  1. cargo new outer && cd outer
  2. cargo new inner
  3. printf '[workspace]\nmembers = ["inner"]' >> Cargo.toml
  4. cd src
  5. cargo fmt

Possible Solution(s)

cargo fmt should format all packages in the workspace, like it does from the top-level directory.

Notes

Output of cargo version:

cargo 1.48.0-nightly (875e01232 2020-09-08) (but the problem also occurs on 1.46 stable)

@jyn514 jyn514 added the C-bug Category: bug label Sep 22, 2020
@ehuss
Copy link
Contributor

ehuss commented Sep 22, 2020

This seems like an issue for rustfmt. Can you move this to that issue tracker? https://github.com/rust-lang/rustfmt/issues

@jyn514
Copy link
Member Author

jyn514 commented Sep 22, 2020

I opened rust-lang/rustfmt#4432

@jyn514 jyn514 closed this as completed Sep 22, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants