{"id":"b084ebd21e190c9a","repo":"rust-lang/cargo","slug":"cannot-specify-both-version-and-version-v","errorCode":null,"errorMessage":"cannot specify both `@<VERSION>` and `--version <VERSION>`","messagePattern":"cannot specify both `@<VERSION>` and `--version <VERSION>`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/install.rs","lineNumber":335,"sourceCode":"                        \"\\n\\n  tip: if you want to specify SemVer range, \\\n                             add an explicit qualifier, like '^{}'\",\n                        v\n                    ));\n                }\n                bail!(msg);\n            }\n        }\n    }\n}\n\nfn resolve_crate(\n    krate: String,\n    local_version: Option<VersionReq>,\n    version: Option<&VersionReq>,\n) -> crate::CargoResult<CrateVersion> {\n    let version = match (local_version, version) {\n        (Some(_), Some(_)) => {\n            anyhow::bail!(\"cannot specify both `@<VERSION>` and `--version <VERSION>`\");\n        }\n        (Some(l), None) => Some(l),\n        (None, Some(g)) => Some(g.to_owned()),\n        (None, None) => None,\n    };\n    Ok((krate, version))\n}\n","sourceCodeStart":317,"sourceCodeEnd":343,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/install.rs#L317-L343","documentation":"From resolve_crate (src/bin/cargo/commands/install.rs:328-342). Each crate spec may carry an inline version via `crate@version` (local_version) and the command also accepts a global --version flag. If both are present for the same crate, Cargo bails because the two sources of version requirements would conflict.","triggerScenarios":"`cargo install ripgrep@1.2.3 --version 1.2.3` or any combination where both the `@version` shorthand and `--version` are supplied.","commonSituations":"Mixing shorthand and explicit flag in a script; copy-pasting from two examples; automating install with redundant version specifiers.","solutions":["Pick one: use either `crate@version` OR `--version <ver>`, not both.","Prefer `--version` when installing multiple crates with the same requirement.","Prefer `crate@version` when each crate needs a distinct version."],"exampleFix":"// before\ncargo install ripgrep@1.2.3 --version 1.2.3\n\n// after\ncargo install ripgrep@1.2.3   # or: cargo install ripgrep --version 1.2.3","handlingStrategy":"validation","validationCode":"// Allow at most one source of version requirement per crate\nfn version_sources_ok(has_at_version: bool, has_version_flag: bool) -> bool {\n    !(has_at_version && has_version_flag)\n}","typeGuard":"fn has_single_version_source(spec: &str, version_flag_present: bool) -> bool {\n    !(spec.contains('@') && version_flag_present)\n}","tryCatchPattern":null,"preventionTips":["Choose one version channel: inline `crate@ver` or `--version ver`, not both.","In automation, derive the version once and pass it through a single flag."],"tags":["cargo","install","version","cli"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}