rust-lang/cargo · 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
The `[patch]` target source contains zero packages matching the patched dependency name. After collecting available versions (`vers`), if `found.is_empty()` the registry bails: the patch points at a source that has no crate by that name. This is the `found.is_empty()` branch at registry.rs:1040.
Solutions
- Verify the package name in the patch exactly matches a package in the target source.
- Check the patch URL/path is correct and the source is reachable.
- If the crate was renamed, update the patch key and dependency to the new name.
Example fix
# before
[patch.crates-io]
foo = { git = "https://example.com/wrong-repo" }
# after
[patch.crates-io]
foo = { git = "https://example.com/correct-repo" } Defensive patterns
Strategy: validation
Validate before calling
// Confirm the target source actually contains the named package
fn patch_source_has_package(available_names: &[&str], patched_name: &str) -> bool {
available_names.iter().any(|n| *n == patched_name)
} Prevention
- Verify the patch URL/path hosts a crate with the exact patched name.
- Watch for crate renames; update both dep and patch keys.
- Clone the patch source and run `cargo metadata` to list package names.
When it happens
Trigger: `[patch.crates-io] foo = { git = "https://..." }` but the git repo has no package named `foo` (typo, wrong repo, or the crate was renamed/removed).
Common situations: Typo in the package name or repo URL. Pointing a patch at a repo that hosts a differently-named crate. The upstream crate was renamed but the patch still uses the old name.
Related errors
- patch for ` ` points to the same source, but patches must…
- found patches and a path override
- patch for ` ` in ` ` resolved to more than one…
- patch ` ` version mismatch note: patch location contains …
- several `[patch]` entries resolving to same version
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/f30b7894b2f37ff9.
Report an issue: GitHub.
Appendix: source
Thrown at src/workspace/registry.rs:1062
});
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 98a09e7e7d)