rust-lang/cargo · error
cannot specify both `@<VERSION>` and `--version <VERSION>`
Error message
cannot specify both `@<VERSION>` and `--version <VERSION>`
What it means
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.
Source
Thrown at src/bin/cargo/commands/install.rs:335
"\n\n tip: if you want to specify SemVer range, \
add an explicit qualifier, like '^{}'",
v
));
}
bail!(msg);
}
}
}
}
fn resolve_crate(
krate: String,
local_version: Option<VersionReq>,
version: Option<&VersionReq>,
) -> crate::CargoResult<CrateVersion> {
let version = match (local_version, version) {
(Some(_), Some(_)) => {
anyhow::bail!("cannot specify both `@<VERSION>` and `--version <VERSION>`");
}
(Some(l), None) => Some(l),
(None, Some(g)) => Some(g.to_owned()),
(None, None) => None,
};
Ok((krate, version))
}
View on GitHub (pinned to 0e07a15537)
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.
Example fix
// before cargo install ripgrep@1.2.3 --version 1.2.3 // after cargo install ripgrep@1.2.3 # or: cargo install ripgrep --version 1.2.3
Defensive patterns
Strategy: validation
Validate before calling
// Allow at most one source of version requirement per crate
fn version_sources_ok(has_at_version: bool, has_version_flag: bool) -> bool {
!(has_at_version && has_version_flag)
} Type guard
fn has_single_version_source(spec: &str, version_flag_present: bool) -> bool {
!(spec.contains('@') && version_flag_present)
} Prevention
- 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.
When it happens
Trigger: `cargo install ripgrep@1.2.3 --version 1.2.3` or any combination where both the `@version` shorthand and `--version` are supplied.
Common situations: Mixing shorthand and explicit flag in a script; copy-pasting from two examples; automating install with redundant version specifiers.
Related errors
- missing crate name before '@'
- invalid character `+` in package name: `+{toolchain}` Us
- invalid package name: `{url}` Use `cargo install --git {
- crate name is empty
- argument for --color must be auto, always, or never, but fou
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/b084ebd21e190c9a.json.
Report an issue: GitHub.