Skip to content

Commit c955b59

Browse files
calebcartwrighttopecongiro
authored andcommitted
fix: run in sub dirs/workspace member dirs (#3652)
1 parent 9986b9d commit c955b59

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/cargo-fmt/main.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,25 @@ fn get_targets_root_only(targets: &mut BTreeSet<Target>) -> Result<(), io::Error
253253
let workspace_root_path = PathBuf::from(&metadata.workspace_root).canonicalize()?;
254254
let in_workspace_root = workspace_root_path == current_dir;
255255

256-
for package in metadata.packages {
257-
if in_workspace_root || PathBuf::from(&package.manifest_path) == current_dir_manifest {
258-
for target in package.targets {
259-
targets.insert(Target::from_target(&target));
260-
}
261-
}
256+
let package_targets = match metadata.packages.len() {
257+
1 => metadata.packages.into_iter().next().unwrap().targets,
258+
_ => metadata
259+
.packages
260+
.into_iter()
261+
.filter(|p| {
262+
in_workspace_root
263+
|| PathBuf::from(&p.manifest_path)
264+
.canonicalize()
265+
.unwrap_or_default()
266+
== current_dir_manifest
267+
})
268+
.map(|p| p.targets)
269+
.flatten()
270+
.collect(),
271+
};
272+
273+
for target in package_targets {
274+
targets.insert(Target::from_target(&target));
262275
}
263276

264277
Ok(())

0 commit comments

Comments
 (0)