{"id":"8bca4112e614bbcd","repo":"rust-lang/cargo","slug":"cannot-specify-both-v-and-version","errorCode":null,"errorMessage":"cannot specify both `@{v}` and `--version`","messagePattern":"cannot specify both `@(.+?)` and `--version`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/yank.rs","lineNumber":55,"sourceCode":"\n    ops::yank(\n        gctx,\n        krate.map(|s| s.to_string()),\n        version.map(|s| s.to_string()),\n        args.get_one::<String>(\"token\").cloned().map(Secret::from),\n        args.registry_or_index(gctx)?,\n        args.flag(\"undo\"),\n    )?;\n    Ok(())\n}\n\nfn resolve_crate<'k>(\n    mut krate: Option<&'k str>,\n    mut version: Option<&'k str>,\n) -> crate::CargoResult<(Option<&'k str>, Option<&'k str>)> {\n    if let Some((k, v)) = krate.and_then(|k| k.split_once('@')) {\n        if version.is_some() {\n            anyhow::bail!(\"cannot specify both `@{v}` and `--version`\");\n        }\n        if k.is_empty() {\n            // by convention, arguments starting with `@` are response files\n            anyhow::bail!(\"missing crate name for `@{v}`\");\n        }\n        krate = Some(k);\n        version = Some(v);\n    }\n\n    if let Some(version) = version {\n        semver::Version::parse(version).with_context(|| {\n            if let Some(stripped) = version.strip_prefix(\"v\") {\n                return format!(\n                    \"the version provided, `{version}` is not a \\\n                    valid SemVer version\\n\\n\\\n                    help: try changing the version to `{stripped}`\",\n                );\n            }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/yank.rs#L37-L73","documentation":"In `cargo yank`'s resolve_crate (yank.rs:53-56), a crate spec written as `crate@version` is split on `@`. If the user ALSO passed `--version <ver>`, the version is now specified twice (once inline, once via flag), which is ambiguous, so Cargo bails.","triggerScenarios":"Running `cargo yank mycrate@1.2.3 --version 1.2.3` (or any combination where both the `@` form and `--version` are present).","commonSituations":"Copy-pasting a version in two places; transitioning between the two syntaxes and forgetting to remove one; shell aliases that inject `--version`.","solutions":["Use only ONE version source: `cargo yank mycrate@1.2.3` OR `cargo yank mycrate --version 1.2.3`.","Remove the redundant `--version` flag (the `@` form is usually more concise)."],"exampleFix":"// before\n$ cargo yank mycrate@1.2.3 --version 1.2.3\nerror: cannot specify both `@1.2.3` and `--version`\n\n// after\n$ cargo yank mycrate@1.2.3","handlingStrategy":"validation","validationCode":"let has_at = crate_spec.as_deref().is_some_and(|s| s.contains('@'));\nlet has_version_flag = version_flag.is_some();\nif has_at && has_version_flag {\n    return Err(\"specify version via @ OR --version, not both\");\n}","typeGuard":"fn version_specified_twice(spec: Option<&str>, ver: Option<&str>) -> bool {\n    spec.map(|s| s.contains('@')).unwrap_or(false) && ver.is_some()\n}\n","tryCatchPattern":null,"preventionTips":["Adopt one version style (prefer `crate@version`) across scripts.","Strip --version from aliases that already use the @ form."],"tags":["cargo","yank","publish","cli","argument"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}