rust-lang/cargo · error · anyhow::Error

could not find `{}` in registry `{}`

Error message

could not find `{}` in registry `{}`

What it means

Thrown by `find_pkgid_in_summaries` when resolving a package spec for `cargo info` (or registry info lookups): after filtering all summaries fetched from a registry, none matched the normalized `PackageIdSpec` (name/version/source). The function picks the MSRV-compatible, then highest-version candidate; if that set is empty it bails. It means the package identifier you supplied does not correspond to any published crate in the queried registry source.

Source

Thrown at src/ops/registry/cargo_info/mod.rs:206

                .unwrap_or_else(|| false);
            let s2_matches = s2
                .rust_version()
                .map(|v| v.is_compatible_with(rustc_version))
                .unwrap_or_else(|| false);
            // MSRV compatible version is preferred.
            match (s1_matches, s2_matches) {
                (true, false) => std::cmp::Ordering::Greater,
                (false, true) => std::cmp::Ordering::Less,
                // If both summaries match the current Rust version or neither do, try to
                // pick the latest version.
                _ => s1.package_id().version().cmp(s2.package_id().version()),
            }
        });

    match summary {
        Some(summary) => Ok(summary.package_id()),
        None => {
            anyhow::bail!(
                "could not find `{}` in registry `{}`",
                normalized_spec,
                source_ids.original.url()
            )
        }
    }
}

fn query_summaries(
    spec: &PackageIdSpec,
    registry: &mut PackageRegistry<'_>,
    source_ids: &RegistrySourceIds,
) -> CargoResult<(Vec<Summary>, Option<String>)> {
    // Query without version requirement to get all index summaries.
    let dep = Dependency::parse(spec.name(), None, source_ids.original)?;
    // Use normalized crate name lookup for user-provided package names.
    let results: Vec<_> = crate::util::block_on(registry.query_vec(&dep, QueryKind::Normalized))?
        .into_iter()

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Verify the crate name spelling and that it exists: `cargo search <name>` or check https://crates.io/crates/<name>.
  2. Loosen or correct the version requirement in the spec (e.g. drop an exact `@x.y.z` that doesn't exist).
  3. Run `cargo update -p <name> --dry-run` or `cargo fetch` to refresh the local registry index, then retry.
  4. If using a private registry, confirm it is configured in `.cargo/config.toml` under `[registries]`/`[source]` and that it actually mirrors the crate.

Example fix

// before
cargo info serde@999.0.0
// after
cargo info serde      // or a real published version
Defensive patterns

Strategy: validation

Validate before calling

// Before calling cargo info, confirm the crate exists and pick a real version:
// $ cargo search <name>   (or query the registry index)
// In build scripts, validate the spec against crates.io before passing to cargo info:
fn crate_exists(name: &str) -> bool {
    // e.g. HEAD https://static.crates.io/crates/<name>/<name>-<version>.crate metadata
    // or parse the sparse index response
    std::process::Command::new("cargo")
        .args(["search", name]).status().map(|s| s.success()).unwrap_or(false)
}

Prevention

When it happens

Trigger: Calling `cargo info <spec>` where `<spec>` names a crate/version that does not exist in the configured registry, or specifying a version requirement that no published version satisfies (e.g. `cargo info serde@=>99.0.0`). Also reached when a `[dependencies]` entry references a crate name absent from crates.io or a private registry, during the info/lookup path rather than the build path.

Common situations: Typos in crate names; requesting a version newer than what's published; pointing at a private/alternate registry (via `.cargo/config.toml` source replacement) that does not mirror the crate; using `cargo info` against a sparse/local registry that hasn't been updated. Also seen after a crate was yanked or renamed.

Related errors


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