mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-12 08:36:03 +00:00
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:
parent
dc2f1429e7
commit
53dcb0d09d
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user