rust-lang/cargo · error

missing crate name before '@'

Error message

missing crate name before '@'

What it means

From parse_crate (src/bin/cargo/commands/install.rs:256-269). It splits a crate spec on the first `@`; if the part before `@` is empty (the argument starts with `@`), it bails. By convention arguments starting with `@` are response files, so an empty crate name before `@` is treated as a user error rather than silently consuming a response file.

Source

Thrown at src/bin/cargo/commands/install.rs:260

            krates,
            source,
            from_cwd,
            &compile_opts,
            args.flag("force"),
            args.flag("no-track"),
            args.dry_run(),
        )?;
    }
    Ok(())
}

type CrateVersion = (String, Option<VersionReq>);

fn parse_crate(krate: &str) -> crate::CargoResult<CrateVersion> {
    let (krate, version) = if let Some((k, v)) = krate.split_once('@') {
        if k.is_empty() {
            // by convention, arguments starting with `@` are response files
            anyhow::bail!("missing crate name before '@'");
        }
        let krate = k.to_owned();
        let version = Some(parse_semver_flag(v)?);
        (krate, version)
    } else {
        let krate = krate.to_owned();
        let version = None;
        (krate, version)
    };

    if krate.is_empty() {
        anyhow::bail!("crate name is empty");
    }

    Ok((krate, version))
}

/// Parses x.y.z as if it were =x.y.z, and gives CLI-specific error messages in the case of invalid

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Put the crate name before `@`: `cargo install <crate>@<version>`.
  2. If you meant a response file, note `cargo install` crate args don't support `@file` syntax there; pass versions via --version.
  3. Use `--version <ver>` instead of the `@version` shorthand.

Example fix

// before
cargo install @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

// Ensure a crate@version spec has a non-empty name before the @
fn parse_crate_spec(s: &str) -> Option<(&str, Option<&str>)> {
    match s.split_once('@') {
        Some((name, ver)) if !name.is_empty() => Some((name, Some(ver))),
        Some(_) => None, // missing name before @
        None => Some((s, None)),
    }
}

Type guard

fn has_crate_name_before_at(s: &str) -> bool {
    match s.find('@') {
        Some(0) => false,
        _ => true,
    }
}

Prevention

When it happens

Trigger: `cargo install @1.2.3` (intending crate@version but omitting the name), or any spec where `@` is the first character.

Common situations: Typing the version-first form; forgetting the crate name; intending a response file (e.g. @args.txt) where Cargo install doesn't support response files for the crate position.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/42e6f867b55eb589.json. Report an issue: GitHub.