From f22b84f8d41084b7260de4618825be89df20a6b5 Mon Sep 17 00:00:00 2001 From: lemorage Date: Thu, 5 Jun 2025 04:30:50 +0200 Subject: [PATCH 1/2] test(workspace): clippy fix work on all crate members --- tests/testsuite/workspaces.rs | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 707b81a167c..64cdbc506a4 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -2716,3 +2716,43 @@ fn nonexistence_package_together_with_workspace() { "#]]) .run(); } + +// A failing case from +#[cargo_test] +fn clippy_fix_all_members_in_a_workspace() { + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["foo", "bar"] + resolver = "3" + "#, + ) + .file( + "foo/Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2021" + "#, + ) + .file("foo/src/main.rs", "fn main() {}") + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.1.0" + edition = "2021" + "#, + ) + .file("bar/src/main.rs", "fn main() {}") + .build(); + + p.cargo("clippy --manifest-path foo/Cargo.toml --fix --allow-no-vcs") + .with_stderr_contains("[CHECKING] foo v0.1.0 ([ROOT]/foo/foo)") + .with_stderr_contains("[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)") + .run(); +} From 304a7a07480a091aa472168f712ada62433d7c92 Mon Sep 17 00:00:00 2001 From: lemorage Date: Thu, 5 Jun 2025 13:25:04 +0200 Subject: [PATCH 2/2] fix(workspace): reload current manifest only --- src/cargo/core/workspace.rs | 2 +- tests/testsuite/workspaces.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 4f28a4efb14..57e50ebefee 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -306,7 +306,7 @@ impl<'gctx> Workspace<'gctx> { /// This is useful if the workspace has been updated, such as with `cargo /// fix` modifying the `Cargo.toml` file. pub fn reload(&self, gctx: &'gctx GlobalContext) -> CargoResult> { - let mut ws = Workspace::new(self.root_manifest(), gctx)?; + let mut ws = Workspace::new(&self.current_manifest, gctx)?; ws.set_resolve_honors_rust_version(Some(self.resolve_honors_rust_version)); ws.set_resolve_feature_unification(self.resolve_feature_unification); ws.set_requested_lockfile_path(self.requested_lockfile_path.clone()); diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 64cdbc506a4..8ae6bc37a01 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -2719,7 +2719,7 @@ fn nonexistence_package_together_with_workspace() { // A failing case from #[cargo_test] -fn clippy_fix_all_members_in_a_workspace() { +fn fix_only_check_manifest_path_member() { let p = project() .file( "Cargo.toml", @@ -2751,8 +2751,11 @@ fn clippy_fix_all_members_in_a_workspace() { .file("bar/src/main.rs", "fn main() {}") .build(); - p.cargo("clippy --manifest-path foo/Cargo.toml --fix --allow-no-vcs") - .with_stderr_contains("[CHECKING] foo v0.1.0 ([ROOT]/foo/foo)") - .with_stderr_contains("[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)") + p.cargo("fix --manifest-path foo/Cargo.toml --allow-no-vcs") + .with_stderr_data(str![[r#" +[CHECKING] foo v0.1.0 ([ROOT]/foo/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); }