rust-lang/cargo · error
missing crate name for `@{v}`
Error message
missing crate name for `@{v}` What it means
In resolve_crate (yank.rs:57-60), when the crate argument starts with `@` (i.e. split_once('@') yields an empty left side), the crate name is missing. By Cargo convention a leading `@` denotes a response file, so a bare `@version` is treated as a crate-less spec and rejected.
Source
Thrown at src/bin/cargo/commands/yank.rs:59
version.map(|s| s.to_string()),
args.get_one::<String>("token").cloned().map(Secret::from),
args.registry_or_index(gctx)?,
args.flag("undo"),
)?;
Ok(())
}
fn resolve_crate<'k>(
mut krate: Option<&'k str>,
mut version: Option<&'k str>,
) -> crate::CargoResult<(Option<&'k str>, Option<&'k str>)> {
if let Some((k, v)) = krate.and_then(|k| k.split_once('@')) {
if version.is_some() {
anyhow::bail!("cannot specify both `@{v}` and `--version`");
}
if k.is_empty() {
// by convention, arguments starting with `@` are response files
anyhow::bail!("missing crate name for `@{v}`");
}
krate = Some(k);
version = Some(v);
}
if let Some(version) = version {
semver::Version::parse(version).with_context(|| {
if let Some(stripped) = version.strip_prefix("v") {
return format!(
"the version provided, `{version}` is not a \
valid SemVer version\n\n\
help: try changing the version to `{stripped}`",
);
}
format!("invalid version `{version}`")
})?;
}
View on GitHub (pinned to 0e07a15537)
Solutions
- Provide the crate name: `cargo yank mycrate@1.2.3` or `cargo yank mycrate --version 1.2.3`.
- If you intended a response file, use a real `@file` argument to a subcommand that supports it — `yank` does not.
Example fix
// before $ cargo yank @1.2.3 error: missing crate name for `@1.2.3` // after $ cargo yank mycrate@1.2.3
Defensive patterns
Strategy: validation
Validate before calling
if let Some(spec) = &crate_arg {
if spec.starts_with('@') {
return Err("missing crate name before @; use crate@version");
}
} Type guard
fn has_crate_before_at(spec: &str) -> bool {
match spec.split_once('@') {
Some((k, _)) => !k.is_empty(),
None => true,
}
}
Prevention
- Always write the crate name before @ when using inline version.
- Sanitize yank args in scripts to ensure a non-empty crate token.
When it happens
Trigger: Running `cargo yank @1.2.3` (version given but no crate name before the `@`).
Common situations: Forgetting the crate name; assuming `--version` style works positionally as `@version`; shell expansion that dropped the crate token.
Related errors
- cannot specify both `@{v}` and `--version`
- {}
- "--package <SPEC>" requires a SPEC format value. Run `cargo
- argument for --color must be auto, always, or never, but fou
- subcommand is required, add a subcommand to the command alia
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/229c881deea2421d.json.
Report an issue: GitHub.