rust-lang/cargo · error · anyhow::Error
patch for `{}` in `{}` resolved to more than one candidate n
Error message
patch for `{}` in `{}` resolved to more than one candidate
note: found versions: {}
help: check `{}` patch definition for `{}` in `{}`
help: select only one package using `version = "={}"` What it means
Error "patch for `{}` in `{}` resolved to more than one candidate note: found versions: {} help: check `{}` patch definition for `{}` in `{}` help: select only one package using `version = "={}"`" thrown in rust-lang/cargo.
Source
Thrown at src/workspace/registry.rs:959
locked: &Option<LockedPatchDependency>,
mut summaries: Vec<Summary>,
source: &dyn Source,
) -> CargoResult<(Summary, Option<PackageId>)> {
if summaries.len() == 1 {
return Ok((summaries.pop().unwrap(), None));
}
if summaries.len() > 1 {
// TODO: In the future, it might be nice to add all of these
// candidates so that version selection would just pick the
// appropriate one. However, as this is currently structured, if we
// added these all as patches, the unselected versions would end up in
// the "unused patch" listing, and trigger a warning. It might take a
// fair bit of restructuring to make that work cleanly, and there
// isn't any demand at this time to support that.
let mut vers: Vec<_> = summaries.iter().map(|summary| summary.version()).collect();
vers.sort();
let versions: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
return Err(anyhow::anyhow!(
"patch for `{}` in `{}` resolved to more than one candidate\n\
note: found versions: {}\n\
help: check `{}` patch definition for `{}` in `{}`\n\
help: select only one package using `version = \"={}\"`",
&original_patch.dep.package_name(),
&original_patch.dep.source_id(),
versions.join(", "),
&original_patch.dep.package_name(),
orig_patch_url,
original_patch.loc,
versions.last().unwrap()
));
}
assert!(summaries.is_empty());
// No summaries found, try to help the user figure out what is wrong.
if let Some(locked) = locked {
// Since the locked patch did not match anything, try the unlocked one.
let orig_matches = sourceView on GitHub (pinned to 0e07a15537)
Solutions
- Narrow the patch with `version = "=<version>"` so it selects exactly one candidate.
- Remove duplicate packages from the patch location.
When it happens
Trigger: Thrown at src/workspace/registry.rs:959 when the library encounters an invalid state.
Common situations: Occurs when a `[patch]` entry matches multiple candidate versions at its location. Constrain the patch with an exact version, e.g. `version = "=1.2.3"`, so only one candidate matches.
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/24a764135e223c78.json.
Report an issue: GitHub.