{"id":"f7001fc9d783f130","repo":"rust-lang/cargo","slug":"was-defined-in-but-could-not-be-resolved-w","errorCode":null,"errorMessage":"`{}` was defined in {} but could not be resolved with {}","messagePattern":"`(.+?)` was defined in (.+?) but could not be resolved with (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/workspace.rs","lineNumber":2142,"sourceCode":"                        \"ignoring `registries.{name}.min-publish-age` without `-Zmin-publish-age`\"\n                    ))?;\n                }\n            }\n        }\n    }\n\n    Ok(())\n}\n\npub fn resolve_relative_path(\n    label: &str,\n    old_root: &Path,\n    new_root: &Path,\n    rel_path: &str,\n) -> CargoResult<String> {\n    let joined_path = normalize_path(&old_root.join(rel_path));\n    match diff_paths(joined_path, new_root) {\n        None => Err(anyhow!(\n            \"`{}` was defined in {} but could not be resolved with {}\",\n            label,\n            old_root.display(),\n            new_root.display()\n        )),\n        Some(path) => Ok(path\n            .to_str()\n            .ok_or_else(|| {\n                anyhow!(\n                    \"`{}` resolved to non-UTF value (`{}`)\",\n                    label,\n                    path.display()\n                )\n            })?\n            .to_owned()),\n    }\n}\n","sourceCodeStart":2124,"sourceCodeEnd":2160,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/workspace.rs#L2124-L2160","documentation":"Returned by `resolve_relative_path` (src/workspace/registry.rs is wrong — actual: src/workspace/workspace.rs:2142) when `diff_paths(joined_path, new_root)` returns `None`, meaning the path formed by joining `old_root` + `rel_path` does not lie underneath `new_root`. Cargo cannot express a relative path between the two trees, so it errors naming the label, where it was defined, and the target root it failed to resolve against.","triggerScenarios":"Calling `resolve_relative_path(label, old_root, new_root, rel_path)` where `old_root.join(rel_path)` canonicalizes outside of `new_root` — e.g. the relative path escapes via `..` components, or `new_root` is not an ancestor of the joined path.","commonSituations":"Workspace relocation where a patch/path dependency referenced by a relative `..` no longer sits under the new workspace root; publishing or packaging with a rewritten root; symlinks causing `diff_paths` to disagree about ancestry.","solutions":["Verify `rel_path` (with `..`) still resolves under `new_root` after the move; adjust the manifest path to point inside the new root.","Ensure `old_root` and `new_root` are both absolute and canonicalized before calling.","If the path legitimately lives outside the new root, switch the manifest to an absolute path or a registry/git dependency instead of a relative one."],"exampleFix":"// before\nlet p = resolve_relative_path(\"dep\", &old_root, &new_root, \"../../outside/dep\")?;\n// after — move dep under new_root and reference relatively\nlet p = resolve_relative_path(\"dep\", &old_root, &new_root, \"members/dep\")?;","handlingStrategy":"validation","validationCode":"use std::path::{Path, Component};\nfn is_under(new_root: &Path, joined: &Path) -> bool {\n    let joined = std::fs::canonicalize(joined).unwrap_or_else(|_| joined.to_path_buf());\n    let new_root = std::fs::canonicalize(new_root).unwrap_or_else(|_| new_root.to_path_buf());\n    joined.starts_with(new_root)\n}\n// before calling resolve_relative_path, assert is_under(&new_root, &old_root.join(rel_path))","typeGuard":null,"tryCatchPattern":"// best-effort: fall back to an absolute path string\nlet p = resolve_relative_path(label, &old_root, &new_root, rel)\n    .unwrap_or_else(|_| old_root.join(rel).to_string_lossy().into_owned());","preventionTips":["Keep patched/path dependencies inside the workspace root.","Canonicalize both roots before computing relative paths.","Avoid `..` escapes in dependency paths."],"tags":["cargo","path","workspace","relative-path"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}