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

patch location `{}` does not contain packages matching `{}`

Error message

patch location `{}` does not contain packages matching `{}`
help: check `{}` patch definition for `{}` in `{}`

What it means

Error "patch location `{}` does not contain packages matching `{}` help: check `{}` patch definition for `{}` in `{}`" thrown in rust-lang/cargo.

Source

Thrown at src/workspace/registry.rs:1041

        });
    let mut vers = name_summaries
        .iter()
        .filter_map(|s| match s {
            IndexSummary::Candidate(s) => Some(s.version()),
            _ => None,
        })
        .collect::<Vec<_>>();
    let found = match vers.len() {
        0 => "".to_string(),
        1 => format!("version `{}`", vers[0]),
        _ => {
            vers.sort();
            let strs: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
            format!("versions `{}`", strs.join(", "))
        }
    };
    Err(if found.is_empty() {
        anyhow::anyhow!(
            "patch location `{}` does not contain packages matching `{}`\n\
            help: check `{}` patch definition for `{}` in `{}`",
            &original_patch.dep.source_id(),
            &original_patch.dep.package_name(),
            &original_patch.dep.package_name(),
            orig_patch_url,
            original_patch.loc
        )
    } else {
        anyhow::anyhow!(
            "patch `{}` version mismatch\n\
            note: patch location contains {}, but patch definition requires `{}`\n\
            help: check patch location `{}`\n\
            help: check `{}` patch definition for `{}` in `{}`",
            &original_patch.dep.package_name(),
            found,
            &original_patch.dep.version_req(),
            &original_patch.dep.source_id(),

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Fix the patch location so it contains a package with the expected name.
  2. Correct the patch definition (name/source) in the manifest.

When it happens

Trigger: Thrown at src/workspace/registry.rs:1041 when the library encounters an invalid state.

Common situations: Occurs when the source named by a `[patch]` entry contains no package matching the patched name/version. Verify the patch location actually provides the intended package and version.


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