Restore cargo fmt behavior in workspaces

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.
This commit is contained in:
Rob Tsuk 2018-03-06 07:28:08 -07:00
parent dc2f1429e7
commit 53dcb0d09d

View File

@ -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));
}
}
}