From 7fd08f495c360bef85dc027ed7e4bdc425497282 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Fri, 7 Jun 2024 00:44:34 -0700 Subject: [PATCH] Handle Cargo.toml manifests that are symlinks The canonicalize() function resolves symlinks, which would cause targets whose "Cargo.toml" is a symlink to be filtered out. This would cause `cargo-fmt` to print an error "Failed to find targets". Resolves #6184 --- src/cargo-fmt/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index eedb43defb9..3c405c2c8db 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -384,11 +384,10 @@ fn get_targets_root_only( .packages .into_iter() .filter(|p| { + let manifest_path = PathBuf::from(&p.manifest_path); in_workspace_root - || PathBuf::from(&p.manifest_path) - .canonicalize() - .unwrap_or_default() - == current_dir_manifest + || manifest_path == current_dir_manifest + || manifest_path.canonicalize().unwrap_or_default() == current_dir_manifest }) .flat_map(|p| p.targets) .collect(),