{"record":{"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":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":410,"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":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/cargo_add/mod.rs#L392-L428","documentation":"Thrown by cargo add when a dependency is specified with both a version requirement (via crate@version syntax) and a --path flag. These are mutually exclusive: a path source uses whatever version is in the local Cargo.toml, so an explicit version requirement is not applicable.","triggerScenarios":"Running `cargo add foo@1.0 --path ./local-foo` where both the @version suffix and --path flag are present.","commonSituations":"Copy-pasting from a registry-style command and adding --path. Forgetting to remove the version when switching to a local source.","solutions":["Remove the version suffix from the crate spec: `cargo add foo --path ./local-foo`","Or remove --path if you want a registry version: `cargo add foo@1.0`"],"exampleFix":"# before\ncargo add foo@1.0 --path ./local-foo\n# error: cannot specify a path with a version\n\n# after — omit version when using --path\ncargo add foo --path ./local-foo","handlingStrategy":"validation","validationCode":"// Validate that version and path are not both specified\nfn validate_add_args_path(crate_spec: &str, path: Option<&Path>) -> Result<(), String> {\n    let has_version = crate_spec.contains('@');\n    if has_version && path.is_some() {\n        return Err(\"cannot specify a path with a version; remove one\".into());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When using --path, omit the @version suffix from the crate name","When specifying a version, omit the --path flag","Use --path for local development and @version for registry pins, never both"],"tags":["cargo-add","path","dependency","conflict"],"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"}