{"record":{"id":"7ace46dd933665e3","repo":"rust-lang/cargo","slug":"patch-version-mismatch-note-patch-location-c","errorCode":null,"errorMessage":"patch `{}` version mismatch\nnote: patch location contains {}, but patch definition requires `{}`\nhelp: check patch location `{}`\nhelp: check `{}` patch definition for `{}` in `{}`","messagePattern":"patch `(.+?)` version mismatch\nnote: patch location contains (.+?), but patch definition requires `(.+?)`\nhelp: check patch location `(.+?)`\nhelp: check `(.+?)` patch definition for `(.+?)` in `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/registry.rs","lineNumber":1072,"sourceCode":"        1 => format!(\"version `{}`\", vers[0]),\n        _ => {\n            vers.sort();\n            let strs: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();\n            format!(\"versions `{}`\", strs.join(\", \"))\n        }\n    };\n    Err(if found.is_empty() {\n        anyhow::anyhow!(\n            \"patch location `{}` does not contain packages matching `{}`\\n\\\n            help: check `{}` patch definition for `{}` in `{}`\",\n            &original_patch.dep.source_id(),\n            &original_patch.dep.package_name(),\n            &original_patch.dep.package_name(),\n            orig_patch_url,\n            original_patch.loc\n        )\n    } else {\n        anyhow::anyhow!(\n            \"patch `{}` version mismatch\\n\\\n            note: patch location contains {}, but patch definition requires `{}`\\n\\\n            help: check patch location `{}`\\n\\\n            help: check `{}` patch definition for `{}` in `{}`\",\n            &original_patch.dep.package_name(),\n            found,\n            &original_patch.dep.version_req(),\n            &original_patch.dep.source_id(),\n            &original_patch.dep.package_name(),\n            orig_patch_url,\n            original_patch.loc\n        )\n    })\n}\n","sourceCodeStart":1054,"sourceCodeEnd":1087,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/workspace/registry.rs#L1054-L1087","documentation":"The patch source contains the named package, but its version does not satisfy the `version_req` declared in the patch entry. The registry formats `found` (available versions) versus the required version and bails in the `else` branch at registry.rs:1051. Cargo refuses to apply a patch whose version is incompatible with the requirement.","triggerScenarios":"`[patch.crates-io] foo = { version = \"1.0\", git = \"...\" }` but the git repo's `foo` is at `2.0.0`, which does not satisfy `^1.0`.","commonSituations":"Fork drifted to a newer major version while the patch still requires the old one. Forgetting to bump the patch's `version` after the fork releases a new major. Version requirement copied from the original dependency that no longer matches the fork.","solutions":["Update the patch's `version` requirement to match what the source actually provides.","Tag/checkout the source at a version satisfying the requirement.","Loosen the requirement (e.g. `version = \"2.0\"`) if the newer version is acceptable."],"exampleFix":"# before\n[patch.crates-io]\nfoo = { version = \"1.0\", git = \"https://example.com/foo-fork\" }\n# fork is at 2.0.0\n\n# after\n[patch.crates-io]\nfoo = { version = \"2.0\", git = \"https://example.com/foo-fork\" }","handlingStrategy":"validation","validationCode":"fn patch_version_satisfies(available: &[semver::Version], req: &semver::VersionReq) -> bool {\n    available.iter().any(|v| req.matches(v))\n}\n// compare the patch source's published versions against the patch's version_req","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the patch's `version` requirement aligned with the source's actual version.","Bump the requirement when the fork releases a new major.","Use `cargo update` after changing patch versions to refresh resolution."],"tags":["cargo","patch","registry","version-resolution","config"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}