{"record":{"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":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/workspace.rs","lineNumber":2087,"sourceCode":"            .map(|p| p.with_context(|| format!(\"unable to match path to pattern `{}`\", &path)))\n            .collect::<Result<Vec<_>, _>>()?;\n        Ok(res)\n    }\n\n    pub fn inheritable(&self) -> &InheritableFields {\n        &self.inheritable_fields\n    }\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":2069,"sourceCodeEnd":2105,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/workspace/workspace.rs#L2069-L2105","documentation":"`resolve_relative_path` takes a label, an old root, a new root, and a relative path. It joins `old_root` + `rel_path`, normalizes it, then calls `diff_paths(joined, new_root)` to express that path relative to `new_root`. `diff_paths` returns `None` when the two paths do not share a common ancestor (e.g. different drive letters on Windows, or a path that cannot be made relative to the target). In that case the function errors out, naming the label, the old root, and the new root.","triggerScenarios":"Calling `resolve_relative_path` where `old_root.join(rel_path)` cannot be relativized against `new_root` — most commonly on Windows when the roots are on different drives (e.g. `C:\\ws` vs `D:\\out`), or when one path is absolute on a different volume than the other.","commonSituations":"Workspace relocation across volumes (building on a different drive), moving a workspace to a tmpdir on a separate mount, or invoking Cargo with `--remap-path-prefix`-style root changes that cross filesystem boundaries.","solutions":["Ensure both `old_root` and `new_root` live on the same drive/volume so `diff_paths` can compute a relative path.","Use an absolute path for the relocated resource instead of relying on relativization across volumes.","If you control the invocation, pass roots that share a common prefix (same drive letter on Windows, same mount on Unix)."],"exampleFix":"// before: roots on different drives (Windows)\nresolve_relative_path(\"pkg\", Path::new(\"C:\\\\ws\"), Path::new(\"D:\\\\out\"), \"pkg/Cargo.toml\")\n// -> Err(\"`pkg` was defined in C:\\\\ws but could not be resolved with D:\\\\out\")\n\n// after: same drive\nresolve_relative_path(\"pkg\", Path::new(\"C:\\\\ws\"), Path::new(\"C:\\\\out\"), \"pkg/Cargo.toml\")","handlingStrategy":"validation","validationCode":"use std::path::{Path, Component};\nuse same_file::Handle; // or compare components\nfn same_volume(a: &Path, b: &Path) -> bool {\n    // On Windows compare Prefix components; on Unix assume single root unless absolute differ\n    matches!(\n        (a.components().next(), b.components().next()),\n        (Some(Component::RootDir), Some(Component::RootDir))\n    )\n}\n// ensure old_root and new_root share a volume before calling resolve_relative_path","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep workspace relocation targets on the same drive/volume.","Prefer absolute paths when crossing volumes is unavoidable.","On Windows, normalize drive letters before relativization."],"tags":["path","workspace","windows","relativization","cargo"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}