{"id":"6709f02018c180bc","repo":"rust-lang/cargo","slug":"failed-to-find-a-workspace-root","errorCode":null,"errorMessage":"failed to find a workspace root","messagePattern":"failed to find a workspace root","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/parser/mod.rs","lineNumber":1003,"sourceCode":"    workspace_config: &WorkspaceConfig,\n) -> CargoResult<InheritableFields> {\n    match workspace_config {\n        WorkspaceConfig::Root(root) => Ok(root.inheritable().clone()),\n        WorkspaceConfig::Member {\n            root: Some(path_to_root),\n        } => {\n            let path = normalized_path\n                .parent()\n                .unwrap()\n                .join(path_to_root)\n                .join(\"Cargo.toml\");\n            let root_path = paths::normalize_path(&path);\n            inheritable_from_path(gctx, root_path)\n        }\n        WorkspaceConfig::Member { root: None } => {\n            match find_workspace_root(&normalized_path, gctx)? {\n                Some(path_to_root) => inheritable_from_path(gctx, path_to_root),\n                None => Err(anyhow!(\"failed to find a workspace root\")),\n            }\n        }\n    }\n}\n\nfn inheritable_from_path(\n    gctx: &GlobalContext,\n    workspace_path: PathBuf,\n) -> CargoResult<InheritableFields> {\n    // Workspace path should have Cargo.toml at the end\n    let workspace_path_root = workspace_path.parent().unwrap();\n\n    // Let the borrow exit scope so that it can be picked up if there is a need to\n    // read a manifest\n    if let Some(ws_root) = gctx.ws_roots().get(workspace_path_root) {\n        return Ok(ws_root.inheritable().clone());\n    };\n","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/mod.rs#L985-L1021","documentation":"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.","triggerScenarios":"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.","commonSituations":"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`.","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."],"exampleFix":"# before (member, no root above it)\n[dependencies]\nfoo = { workspace = true }\n# after (self-contained)\n[dependencies]\nfoo = \"1.0\"","handlingStrategy":"validation","validationCode":"use cargo::workspace::find_workspace_root;\nif find_workspace_root(&manifest_path, gctx)?.is_none()\n    && uses_inheritance(&manifest)? {\n    return Err(\"no workspace root found for inherited fields\".into());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["workspace","inheritance","parser"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}