Skip to content

cargo fmt only works in root directory of project #3647

Closed
@milkey-mouse

Description

@milkey-mouse

I often leave my shell in the project/src directory so I don't have to prepend src every time I open a file. Other cargo commands such as cargo run and cargo check work fine in the src directory, but cargo fmt does not:

~/projects/planets $ cargo fmt  # works
~/projects/planets $ cargo run  # works
~/projects/planets $ cd src
~/projects/planets/src $ cargo run  # still works
~/projects/planets/src $ cargo fmt
Failed to find targets
cargo-fmt 1.3.0
This utility formats all bin and lib files of the current crate using rustfmt.
# etc., etc.

cargo fmt would more closely resemble other cargo subcommands (and git subcommands, to name another tool with this behavior) if it recursed upwards to find the Cargo.toml first.

I'm using a recent nightly version of rustc, cargo, & rustfmt:

$ rustc --version
rustc 1.37.0-dev (8d6f4b96d 2019-06-21)
$ cargo --version
cargo 1.37.0-dev (807429e1b 2019-06-11)
$ rustfmt --version
rustfmt 1.3.0-dev (d3345024 2019-06-09)
$ cargo fmt --version
rustfmt 1.3.0-dev (d3345024 2019-06-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.good first issueIssues up for grabs, also good candidates for new rustfmt contributors

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions