{"record":{"id":"5d7d07f7d7967ec3","repo":"rust-lang/cargo","slug":"all-dependencies-must-have-a-version-requirement-s","errorCode":null,"errorMessage":"all dependencies must have a version requirement specified when {}.\ndependency `{}` does not specify a version\nNote: The {} dependency will use the version from {},\nthe `{}` specification will be removed from the dependency declaration.","messagePattern":"all dependencies must have a version requirement specified when (.+?)\\.\ndependency `(.+?)` does not specify a version\nNote: The (.+?) dependency will use the version from (.+?),\nthe `(.+?)` specification will be removed from the dependency declaration\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/mod.rs","lineNumber":101,"sourceCode":"/// This check is performed on dependencies before publishing or packaging\nfn check_dep_has_version(\n    dep: &crate::workspace::Dependency,\n    publish: bool,\n) -> crate::CargoResult<bool> {\n    let which = if dep.source_id().is_path() {\n        \"path\"\n    } else if dep.source_id().is_git() {\n        \"git\"\n    } else {\n        return Ok(false);\n    };\n\n    if !dep.specified_req() && dep.is_transitive() {\n        let dep_version_source = dep.registry_id().map_or_else(\n            || CRATES_IO_DOMAIN.to_string(),\n            |registry_id| registry_id.display_registry_name(),\n        );\n        anyhow::bail!(\n            \"all dependencies must have a version requirement specified when {}.\\n\\\n             dependency `{}` does not specify a version\\n\\\n             Note: The {} dependency will use the version from {},\\n\\\n             the `{}` specification will be removed from the dependency declaration.\",\n            if publish { \"publishing\" } else { \"packaging\" },\n            dep.package_name(),\n            if publish { \"published\" } else { \"packaged\" },\n            dep_version_source,\n            which,\n        )\n    }\n    Ok(true)\n}\n","sourceCodeStart":83,"sourceCodeEnd":115,"githubUrl":"https://github.com/rust-lang/cargo/blob/495c385d0875c4ba51eb72ea0448a2d4c018b8d4/src/ops/mod.rs#L83-L115","documentation":"Thrown by `check_dep_has_version` during `cargo package` or `cargo publish` when a path or git dependency does not specify a version requirement (`specified_req()` is false) and the dependency is transitive (will be included in the published artifact). Path/git dependencies need a version field so that when the path/git source is stripped on publish, the registry version can fill in.","triggerScenarios":"Running `cargo package` or `cargo publish` on a crate that has a `[dependencies]` entry with `path = \"...\"` or `git = \"...\"` but no `version = \"...\"` key, and that dependency is non-optional and non-dev-only (transitive).","commonSituations":"Workspace members referencing each other by path without a version; a git dependency declared without a version field; prototyping with path deps and forgetting to add versions before publishing.","solutions":["Add a `version` key to the dependency declaration in Cargo.toml.","If the dependency is dev-only, move it under `[dev-dependencies]` so it is not transitive.","If optional, mark it `optional = true` so it is not required for publish."],"exampleFix":"# Cargo.toml (before)\n[dependencies]\nmy-crate = { path = \"../my-crate\" }\n\n# Cargo.toml (after)\n[dependencies]\nmy-crate = { path = \"../my-crate\", version = \"1.0\" }","handlingStrategy":"validation","validationCode":"fn check_path_git_deps_have_version(manifest: &toml::Value) -> Result<(), String> {\n    let deps = manifest.get(\"dependencies\").and_then(|d| d.as_table());\n    if let Some(deps) = deps {\n        for (name, val) in deps {\n            if let Some(t) = val.as_table() {\n                let has_path_or_git = t.contains_key(\"path\") || t.contains_key(\"git\");\n                let has_version = t.contains_key(\"version\");\n                let optional = t.get(\"optional\").and_then(|o| o.as_bool()).unwrap_or(false);\n                if has_path_or_git && !has_version && !optional {\n                    return Err(format!(\"dependency `{}` has path/git but no version requirement\", name));\n                }\n            }\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always add a `version` field to path and git dependencies.","Run `cargo publish --dry-run` before publishing to catch missing versions.","For dev-only path deps, place them under `[dev-dependencies]`."],"tags":["cargo-package","cargo-publish","dependencies","version-requirement","path","git"],"backgroundTag":null,"analyzedSha":"495c385d0875c4ba51eb72ea0448a2d4c018b8d4","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}