{"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":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/registry.rs","lineNumber":1051,"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":1033,"sourceCodeEnd":1066,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/registry.rs#L1033-L1066","documentation":"Thrown inside `summary_for_patch` when a `[patch]` entry in Cargo.toml resolves to a package that exists at the patch location by name, but none of the versions found there satisfy the version requirement stated in the patch definition. Cargo first queries the patch source by name-only (src/workspace/registry.rs:1008), collects candidate versions, sorts them, and — finding at least one but none matching `version_req()` — constructs this 'version mismatch' anyhow error naming the package, the versions actually present, and the requirement that failed.","triggerScenarios":"A `[patch.crates-io]` table points a dependency at a path/git/registry source where the crate exists but at a different version than the `version = \"...\"` field requires. Concretely: `summary_for_patch` is called with an `original_patch` whose `dep.version_req()` does not intersect any `IndexSummary::Candidate` version returned by `source.query_vec(&name_only_dep, QueryKind::Exact)`.","commonSituations":"Vendoring a crate via `[patch]` and pinning `version = \"2.0\"` while the vendored checkout is actually 1.x; bumping a dependency's version in the patch table but forgetting to update the patched fork; pointing a patch at a git branch whose Cargo.toml version diverged from the requirement; using `cargo vendor` output whose versions drifted from the lockfile.","solutions":["Open the patch location shown in the error and read its Cargo.toml `version` field, then set the patch table's `version =` to a requirement that matches it (e.g. exact `\"1.2.3\"`).","If you want the patch source's version to win, remove the `version` constraint from the patch entry entirely so any version is accepted.","Update or checkout the patched fork to a commit whose version satisfies the stated requirement, then rebuild.","If multiple versions exist at the location, qualify the requirement to pick the intended one (e.g. `version = \">=1.2, <1.3\"`)."],"exampleFix":"// before — patch requires 2.x but the fork is 1.x\n[patch.crates-io]\nserde = { path = \"../serde-fork\", version = \"2.0\" }\n// after — match the fork's actual version\n[patch.crates-io]\nserde = { path = \"../serde-fork\", version = \"1.0\" }\n// or drop the requirement to accept whatever the fork ships\n[patch.crates-io]\nserde = { path = \"../serde-fork\" }","handlingStrategy":"validation","validationCode":"// Before defining a patch, confirm the patch source's version satisfies your requirement.\nuse semver::VersionReq;\nfn patch_version_ok(req: &str, actual: &semver::Version) -> bool {\n    VersionReq::parse(req).map(|r| r.matches(actual)).unwrap_or(false)\n}\n// read ../fork/Cargo.toml version, then assert patch_version_ok(\"^1.0\", &actual)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep patch `version =` constraints in sync with the patched fork's Cargo.toml.","Prefer omitting `version` in patch entries when you always want the fork's version.","Run `cargo update` after changing a patch source to surface mismatches early."],"tags":["cargo","patch","dependency","version-mismatch","manifest"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}