{"id":"560ce7af0134b794","repo":"rust-lang/cargo","slug":"cannot-specify-a-path-raw-path-with-a-versio","errorCode":null,"errorMessage":"cannot specify a path (`{raw_path}`) with a version (`{v}`).","messagePattern":"cannot specify a path \\(`(.+?)`\\) with a version \\(`(.+?)`\\)\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":408,"sourceCode":"        let path = paths::normalize_path(&std::env::current_dir()?.join(raw_path));\n        let mut src = PathSource::new(path);\n        src.base = arg.base.clone();\n\n        if let Some(base) = &arg.base {\n            // Validate that the base is valid.\n            let workspace_root = || Ok(ws.root_manifest().parent().unwrap());\n            lookup_path_base(\n                &PathBaseName::new(base.clone())?,\n                &gctx,\n                &workspace_root,\n                spec.manifest().unstable_features(),\n            )?;\n        }\n\n        let selected = if let Some(crate_spec) = &crate_spec {\n            if let Some(v) = crate_spec.version_req() {\n                // crate specifier includes a version (e.g. `docopt@0.8`)\n                anyhow::bail!(\"cannot specify a path (`{raw_path}`) with a version (`{v}`).\");\n            }\n            let dependency = crate_spec.to_dependency()?.set_source(src);\n            let selected = select_package(&dependency, gctx, registry)?;\n            if dependency.name != selected.name {\n                gctx.shell().warn(format!(\n                    \"translating `{}` to `{}`\",\n                    dependency.name, selected.name,\n                ))?;\n            }\n            selected\n        } else {\n            let source = crate::sources::PathSource::new(&src.path, src.source_id()?, gctx);\n            let package = source.root_package()?;\n            let mut selected = Dependency::from(package.summary());\n            if let Some(Source::Path(selected_src)) = &mut selected.source {\n                selected_src.base = src.base;\n            }\n            selected","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_add/mod.rs#L390-L426","documentation":"Symmetric to the git case: a path source cannot be combined with an inline version requirement. When `--path <p>` is given and the crate spec contains a version (`x@1.0`), cargo-add bails at mod.rs:408 because a path dependency's version comes from the local manifest at that path, not a registry requirement.","triggerScenarios":"`cargo add --path ../libs/foo mycrate@1.0` triggers it; `--path` plus a `crate_spec` with a non-empty `version_req()` is the exact condition.","commonSituations":"Workspace-local path crates where the user reflexively adds a version pin, or scripts that build specs uniformly as `name@version` regardless of source kind.","solutions":["Drop the `@version`: `cargo add --path <dir> <crate>` and let the path crate's own version apply.","If you must pin the path crate, set `version = \"...\"` directly in the path crate's `Cargo.toml`, not on the `cargo add` line.","If a version requirement is truly required, you need a registry/git source rather than `--path`."],"exampleFix":"# before\ncargo add --path ../libs/foo mycrate@1.0\n\n# after\ncargo add --path ../libs/foo mycrate","handlingStrategy":"validation","validationCode":"// A path source cannot carry a version req; reject it up front.\nfn build_path_dep_op(name: &str, path: &str, ver: Option<&str>) -> Result<DepOp, String> {\n    if ver.is_some() {\n        return Err(\"cannot combine --path with a version requirement\".into());\n    }\n    Ok(DepOp { crate_spec: Some(name.into()), path: Some(path.into()), ..Default::default() })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat path crates as version-less; pin the version inside the path crate's own manifest.","Build DepOp via a single validated constructor that knows source-kind rules.","Audit scripts that template `name@version` for all source kinds."],"tags":["cargo-add","path","version","conflict"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}