From 2a76d9553615b23f4df422b2dd133caaa610905f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Campinas?= Date: Fri, 1 Feb 2019 01:02:15 +0100 Subject: [PATCH 1/3] cargo-fmt: skip only the executable name --- src/cargo-fmt/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index 83a93240ff2..a6150e07c93 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -54,7 +54,7 @@ fn execute() -> i32 { // If there is any invalid argument passed to `cargo fmt`, return without formatting. let mut is_package_arg = false; - for arg in env::args().skip(2).take_while(|a| a != "--") { + for arg in env::args().skip(1).take_while(|a| a != "--") { if arg.starts_with('-') { is_package_arg = arg.starts_with("--package") | arg.starts_with("-p"); } else if !is_package_arg { From 06d8feb8a52c33c2f82dd9718440048f85acbb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Campinas?= Date: Sat, 2 Feb 2019 18:37:36 +0100 Subject: [PATCH 2/3] canonicalize on Windows returns an extended-length path which adds a leading "\\?\" which needs to be taken into account apply @jakoschiko fix --- src/cargo-fmt/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index a6150e07c93..5554c7590f3 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -242,7 +242,9 @@ fn get_targets_root_only(targets: &mut HashSet) -> Result<(), io::Error> let in_workspace_root = workspace_root_path == current_dir; for package in metadata.packages { - if in_workspace_root || PathBuf::from(&package.manifest_path) == current_dir_manifest { + if in_workspace_root + || PathBuf::from(&package.manifest_path).canonicalize()? == current_dir_manifest + { for target in package.targets { targets.insert(Target::from_target(&target)); } From ec8ec058a800022ed9718cc0bff1ff776facc0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Campinas?= Date: Tue, 5 Feb 2019 20:54:43 +0100 Subject: [PATCH 3/3] cargo-fmt: skip the first two args which are the bin's name and fmt, when called with 'cargo fmt' --- src/cargo-fmt/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index 5554c7590f3..3886c9da1ea 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -54,7 +54,7 @@ fn execute() -> i32 { // If there is any invalid argument passed to `cargo fmt`, return without formatting. let mut is_package_arg = false; - for arg in env::args().skip(1).take_while(|a| a != "--") { + for arg in env::args().skip(2).take_while(|a| a != "--") { if arg.starts_with('-') { is_package_arg = arg.starts_with("--package") | arg.starts_with("-p"); } else if !is_package_arg {