Skip to content

Commit 2094c9f

Browse files
authored
fix(workspace): reload current manifest path member only (#15633)
### What does this PR try to resolve? As of #15625, the manifest path argument in `cargo clippy --manifest-path foo/Cargo.toml --fix` will be ignored. All the workspace members will be built. The cause is due to the `reload` usage in `cargo::ops::fix`. We reload the `root_manifest` in the function, which contains all workspace members. Will close #15625. ### How to test and review this PR? The first commit in the PR demonstrates the current problem, and the second commit corrects it. Use `cargo test --test testsuite workspaces::fix_only_check_manifest_path_member` to see the test results.
2 parents 1101a25 + 304a7a0 commit 2094c9f

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/cargo/core/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'gctx> Workspace<'gctx> {
306306
/// This is useful if the workspace has been updated, such as with `cargo
307307
/// fix` modifying the `Cargo.toml` file.
308308
pub fn reload(&self, gctx: &'gctx GlobalContext) -> CargoResult<Workspace<'gctx>> {
309-
let mut ws = Workspace::new(self.root_manifest(), gctx)?;
309+
let mut ws = Workspace::new(&self.current_manifest, gctx)?;
310310
ws.set_resolve_honors_rust_version(Some(self.resolve_honors_rust_version));
311311
ws.set_resolve_feature_unification(self.resolve_feature_unification);
312312
ws.set_requested_lockfile_path(self.requested_lockfile_path.clone());

tests/testsuite/workspaces.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,3 +2716,46 @@ fn nonexistence_package_together_with_workspace() {
27162716
"#]])
27172717
.run();
27182718
}
2719+
2720+
// A failing case from <https://github.com/rust-lang/cargo/issues/15625>
2721+
#[cargo_test]
2722+
fn fix_only_check_manifest_path_member() {
2723+
let p = project()
2724+
.file(
2725+
"Cargo.toml",
2726+
r#"
2727+
[workspace]
2728+
members = ["foo", "bar"]
2729+
resolver = "3"
2730+
"#,
2731+
)
2732+
.file(
2733+
"foo/Cargo.toml",
2734+
r#"
2735+
[package]
2736+
name = "foo"
2737+
version = "0.1.0"
2738+
edition = "2021"
2739+
"#,
2740+
)
2741+
.file("foo/src/main.rs", "fn main() {}")
2742+
.file(
2743+
"bar/Cargo.toml",
2744+
r#"
2745+
[package]
2746+
name = "bar"
2747+
version = "0.1.0"
2748+
edition = "2021"
2749+
"#,
2750+
)
2751+
.file("bar/src/main.rs", "fn main() {}")
2752+
.build();
2753+
2754+
p.cargo("fix --manifest-path foo/Cargo.toml --allow-no-vcs")
2755+
.with_stderr_data(str![[r#"
2756+
[CHECKING] foo v0.1.0 ([ROOT]/foo/foo)
2757+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
2758+
2759+
"#]])
2760+
.run();
2761+
}

0 commit comments

Comments
 (0)