rust-lang/cargo · error · anyhow::Error
failed to find a workspace root
Error message
failed to find a workspace root
What it means
Thrown by `inheritable` at src/workspace/parser/mod.rs:1003. When a package is configured as a workspace member with no explicit root (`WorkspaceConfig::Member { root: None }`) — i.e. it relies on workspace inheritance (`workspace = true` on a dependency or `[package] workspace = true`) — cargo walks up the tree via `find_workspace_root`. If no ancestor `Cargo.toml` defines a `[workspace]` table, inheritance cannot resolve and parsing fails.
Source
Thrown at src/workspace/parser/mod.rs:1003
workspace_config: &WorkspaceConfig,
) -> CargoResult<InheritableFields> {
match workspace_config {
WorkspaceConfig::Root(root) => Ok(root.inheritable().clone()),
WorkspaceConfig::Member {
root: Some(path_to_root),
} => {
let path = normalized_path
.parent()
.unwrap()
.join(path_to_root)
.join("Cargo.toml");
let root_path = paths::normalize_path(&path);
inheritable_from_path(gctx, root_path)
}
WorkspaceConfig::Member { root: None } => {
match find_workspace_root(&normalized_path, gctx)? {
Some(path_to_root) => inheritable_from_path(gctx, path_to_root),
None => Err(anyhow!("failed to find a workspace root")),
}
}
}
}
fn inheritable_from_path(
gctx: &GlobalContext,
workspace_path: PathBuf,
) -> CargoResult<InheritableFields> {
// Workspace path should have Cargo.toml at the end
let workspace_path_root = workspace_path.parent().unwrap();
// Let the borrow exit scope so that it can be picked up if there is a need to
// read a manifest
if let Some(ws_root) = gctx.ws_roots().get(workspace_path_root) {
return Ok(ws_root.inheritable().clone());
};
View on GitHub (pinned to 0e07a15537)
Solutions
- Build from the workspace root that contains the `[workspace]` table, or ensure an ancestor dir has one.
- Remove the `workspace = true` / inheritance markers and specify sources directly in the member.
- Add a `[workspace]` section in the nearest appropriate ancestor manifest.
Example fix
# before (member, no root above it)
[dependencies]
foo = { workspace = true }
# after (self-contained)
[dependencies]
foo = "1.0" Defensive patterns
Strategy: validation
Validate before calling
use cargo::workspace::find_workspace_root;
if find_workspace_root(&manifest_path, gctx)?.is_none()
&& uses_inheritance(&manifest)? {
return Err("no workspace root found for inherited fields".into());
} Prevention
- Always build workspace members from a root that defines `[workspace]`.
- Remove `workspace = true` before extracting a crate from its workspace.
- Vendor the root manifest alongside members.
When it happens
Trigger: A crate whose Cargo.toml uses `foo = { workspace = true }` or inherits `[package]` fields but is built standalone outside any workspace; moving a member out of its workspace without updating the manifest.
Common situations: Cloning a single sub-crate from a monorepo; vendoring a member without its root; CI building a path dependency that expects a parent workspace; deleted/renamed the root `Cargo.toml`.
Related errors
- dependency ({}) specified without providing a local path, Gi
- cannot override workspace dependency with `--default-feature
- cannot override workspace dependency with `--registry`, eith
- cannot override workspace dependency with `--rename`, either
- multiple packages found at `{src}`: {} To disambiguate,
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/6709f02018c180bc.json.
Report an issue: GitHub.