From 78f4c0456f462d91c2ebabd83ea871fa020429e1 Mon Sep 17 00:00:00 2001 From: 0xPoe Date: Tue, 24 Feb 2026 08:53:25 +0100 Subject: [PATCH 1/2] test: add the workspace search error case Signed-off-by: 0xPoe fix Signed-off-by: 0xPoe --- tests/testsuite/workspaces.rs | 36 ++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 0f8ab785baf..bbafc31eb05 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -6,7 +6,10 @@ use std::fs; use crate::prelude::*; use cargo_test_support::registry::Package; use cargo_test_support::str; -use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project, sleep_ms}; +use cargo_test_support::{ + ProjectBuilder, basic_lib_manifest, basic_manifest, git, paths, project, project_in_home, + sleep_ms, +}; #[cargo_test] fn simple_explicit() { @@ -2198,6 +2201,37 @@ fn cargo_home_at_root_works() { p.cargo("check --frozen").env("CARGO_HOME", p.root()).run(); } +#[cargo_test] +fn parent_manifest_error_mentions_workspace_search() { + ProjectBuilder::new(paths::home()) + .file( + "Cargo.toml", + r#" + [package] + name = "home-manifest" + version = "0.1.0" + authors = [] + "#, + ) + .build(); + + let p = project_in_home("stuff") + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] failed to parse manifest at `[ROOT]/home/Cargo.toml` + +Caused by: + no targets specified in the manifest + either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present + +"#]]) + .run(); +} + #[cargo_test] fn relative_rustc() { let p = project() From 43f2b102657076107feb693f32c3ebd4dfe440cf Mon Sep 17 00:00:00 2001 From: 0xPoe Date: Tue, 24 Feb 2026 09:50:44 +0100 Subject: [PATCH 2/2] feat: improve parent workspace search error msg Signed-off-by: 0xPoe --- src/cargo/core/workspace.rs | 14 +++++++++++++- tests/testsuite/install.rs | 5 +++++ tests/testsuite/workspaces.rs | 19 ++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index bdf06d60757..fa9f3465a17 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -2398,7 +2398,19 @@ fn find_workspace_root_with_loader( for ances_manifest_path in find_root_iter(manifest_path, gctx) { debug!("find_root - trying {}", ances_manifest_path.display()); - if let Some(ws_root_path) = loader(&ances_manifest_path)? { + let ws_root_path = loader(&ances_manifest_path).with_context(|| { + format!( + "failed searching for potential workspace\n\ + package manifest: `{}`\n\ + invalid potential workspace manifest: `{}`\n\ + \n\ + help: to avoid searching for a non-existent workspace, add \ + `[workspace]` to the package manifest", + manifest_path.display(), + ances_manifest_path.display(), + ) + })?; + if let Some(ws_root_path) = ws_root_path { return Ok(Some(ws_root_path)); } } diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 5791b9aa9b8..1ef45752cac 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -2317,6 +2317,11 @@ fn git_install_reads_workspace_manifest() { | 6 | incremental = 3 | ^ +[ERROR] failed searching for potential workspace +package manifest: `[ROOT]/home/.cargo/git/checkouts/foo-[HASH]/[..]/bin1/Cargo.toml` +invalid potential workspace manifest: `[ROOT]/home/.cargo/git/checkouts/foo-[HASH]/[..]/Cargo.toml` + +[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest "#]]) .run(); diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index bbafc31eb05..afc254b636c 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -1124,6 +1124,11 @@ fn new_warning_with_corrupt_ws() { | ^ [WARNING] compiling this new package may not work due to invalid workspace configuration +failed searching for potential workspace +package manifest: `[ROOT]/foo/bar/Cargo.toml` +invalid potential workspace manifest: `[ROOT]/foo/Cargo.toml` + +[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest [NOTE] see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html "#]]).run(); @@ -1402,6 +1407,11 @@ fn error_if_parent_cargo_toml_is_invalid() { | 1 | Totally not a TOML file | ^ +[ERROR] failed searching for potential workspace +package manifest: `[ROOT]/foo/bar/Cargo.toml` +invalid potential workspace manifest: `[ROOT]/foo/Cargo.toml` + +[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest "#]]) .run(); @@ -2222,7 +2232,14 @@ fn parent_manifest_error_mentions_workspace_search() { p.cargo("check") .with_status(101) .with_stderr_data(str![[r#" -[ERROR] failed to parse manifest at `[ROOT]/home/Cargo.toml` +[ERROR] failed searching for potential workspace +package manifest: `[ROOT]/home/stuff/Cargo.toml` +invalid potential workspace manifest: `[ROOT]/home/Cargo.toml` + +[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest + +Caused by: + failed to parse manifest at `[ROOT]/home/Cargo.toml` Caused by: no targets specified in the manifest