{"id":"24a764135e223c78","repo":"rust-lang/cargo","slug":"patch-for-in-resolved-to-more-than-one-c","errorCode":null,"errorMessage":"patch for `{}` in `{}` resolved to more than one candidate\nnote: found versions: {}\nhelp: check `{}` patch definition for `{}` in `{}`\nhelp: select only one package using `version = \"={}\"`","messagePattern":"patch for `(.+?)` in `(.+?)` resolved to more than one candidate\nnote: found versions: (.+?)\nhelp: check `(.+?)` patch definition for `(.+?)` in `(.+?)`\nhelp: select only one package using `version = \"=(.+?)\"`","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/registry.rs","lineNumber":959,"sourceCode":"    locked: &Option<LockedPatchDependency>,\n    mut summaries: Vec<Summary>,\n    source: &dyn Source,\n) -> CargoResult<(Summary, Option<PackageId>)> {\n    if summaries.len() == 1 {\n        return Ok((summaries.pop().unwrap(), None));\n    }\n    if summaries.len() > 1 {\n        // TODO: In the future, it might be nice to add all of these\n        // candidates so that version selection would just pick the\n        // appropriate one. However, as this is currently structured, if we\n        // added these all as patches, the unselected versions would end up in\n        // the \"unused patch\" listing, and trigger a warning. It might take a\n        // fair bit of restructuring to make that work cleanly, and there\n        // isn't any demand at this time to support that.\n        let mut vers: Vec<_> = summaries.iter().map(|summary| summary.version()).collect();\n        vers.sort();\n        let versions: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();\n        return Err(anyhow::anyhow!(\n            \"patch for `{}` in `{}` resolved to more than one candidate\\n\\\n            note: found versions: {}\\n\\\n            help: check `{}` patch definition for `{}` in `{}`\\n\\\n            help: select only one package using `version = \\\"={}\\\"`\",\n            &original_patch.dep.package_name(),\n            &original_patch.dep.source_id(),\n            versions.join(\", \"),\n            &original_patch.dep.package_name(),\n            orig_patch_url,\n            original_patch.loc,\n            versions.last().unwrap()\n        ));\n    }\n    assert!(summaries.is_empty());\n    // No summaries found, try to help the user figure out what is wrong.\n    if let Some(locked) = locked {\n        // Since the locked patch did not match anything, try the unlocked one.\n        let orig_matches = source","sourceCodeStart":941,"sourceCodeEnd":977,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/registry.rs#L941-L977","documentation":"Error \"patch for `{}` in `{}` resolved to more than one candidate\nnote: found versions: {}\nhelp: check `{}` patch definition for `{}` in `{}`\nhelp: select only one package using `version = \"={}\"`\" thrown in rust-lang/cargo.","triggerScenarios":"Thrown at src/workspace/registry.rs:959 when the library encounters an invalid state.","commonSituations":"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.","solutions":["Narrow the patch with `version = \"=<version>\"` so it selects exactly one candidate.","Remove duplicate packages from the patch location."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}