Skip to content

Commit

Permalink
Restore cargo fmt behavior in workspaces
Browse files Browse the repository at this point in the history
Previously, cargo fmt  invoked without parameters would
only format the crate in the current directory, even if
the crate was part of a workspace. This patch restores
that behavior.
  • Loading branch information
Rob Tsuk committed Mar 9, 2018
1 parent dc2f142 commit 53dcb0d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cargo-fmt/main.rs
Expand Up @@ -249,10 +249,16 @@ fn get_targets(strategy: &CargoFmtStrategy) -> Result<HashSet<Target>, io::Error

fn get_targets_root_only(targets: &mut HashSet<Target>) -> Result<(), io::Error> {
let metadata = get_cargo_metadata(None)?;
let current_dir = env::current_dir()?;
let current_dir_manifest = current_dir.join("Cargo.toml");
let workspace_root_path = PathBuf::from(&metadata.workspace_root);
let in_workspace_root = workspace_root_path == current_dir;

for package in metadata.packages {
for target in package.targets {
targets.insert(Target::from_target(&target));
if in_workspace_root || PathBuf::from(&package.manifest_path) == current_dir_manifest {
for target in package.targets {
targets.insert(Target::from_target(&target));
}
}
}

Expand Down

0 comments on commit 53dcb0d

Please sign in to comment.