{"id":"e14dd66f0a6e6199","repo":"rust-lang/cargo","slug":"dupes-must-be-in-sync","errorCode":null,"errorMessage":"dupes must be in sync","messagePattern":"dupes must be in sync","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/common_for_install_and_uninstall.rs","lineNumber":216,"sourceCode":"                _ => None,\n            })\n            .collect();\n\n        // If both sets are the same length, that means all duplicates come\n        // from packages with the same name.\n        if matching_duplicates.len() == duplicates.len() {\n            // Determine if it is dirty or fresh.\n            let source_id = pkg.package_id().source_id();\n            if source_id.is_path() {\n                // `cargo install --path ...` is always rebuilt.\n                return Ok((Freshness::Dirty(DirtyReason::Forced), duplicates));\n            }\n            let is_up_to_date = |dupe_pkg_id| {\n                let info = self\n                    .v2\n                    .installs\n                    .get(dupe_pkg_id)\n                    .expect(\"dupes must be in sync\");\n                let precise_equal = if source_id.is_git() {\n                    // Git sources must have the exact same hash to be\n                    // considered \"fresh\".\n                    dupe_pkg_id.source_id().has_same_precise_as(source_id)\n                } else {\n                    true\n                };\n\n                dupe_pkg_id.version() == pkg.version()\n                    && dupe_pkg_id.source_id() == source_id\n                    && precise_equal\n                    && info.is_up_to_date(opts, target, &exes)\n            };\n            if matching_duplicates.iter().all(is_up_to_date) {\n                Ok((Freshness::Fresh, duplicates))\n            } else {\n                Ok((Freshness::Dirty(DirtyReason::Forced), duplicates))\n            }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/common_for_install_and_uninstall.rs#L198-L234","documentation":"Invariant in `cargo install`/`uninstall` freshness tracking: `self.v2.installs.get(dupe_pkg_id).expect(\"dupes must be in sync\")`. When a duplicate package is found, cargo assumes it has a matching install record in the `v2` tracker. The panic fires if a duplicate package id is not present in the installs map.","triggerScenarios":"Running `cargo install` (or `cargo uninstall`) when the on-disk install tracking metadata (`~/.cargo/.crates2.json`) lists duplicate package ids but the install-info entries disagree — i.e. the duplicates set and the installs map are inconsistent.","commonSituations":"Corrupted `.crates2.json` from a crash during install/uninstall; manual editing of the tracker; a cargo bug leaving a stale duplicate entry; mixed cargo versions writing the tracker with different id formats (e.g. git precise-fragment changes).","solutions":["Inspect `~/.cargo/.crates2.json` for duplicate/stale entries; back it up first.","Remove the orphaned install: `cargo uninstall <crate>` for the listed duplicate, or delete the stale entry from `.crates2.json`.","If the tracker is badly corrupted, remove `.crates2.json` (you lose the install ledger) and reinstall crates as needed.","Report a cargo bug with the contents of `.crates2.json` (redact tokens) if it reproduces on fresh state."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before install/uninstall freshness checks, back up and validate .crates2.json.\nlet tracker = std::fs::read(\"~/.cargo/.crates2.json\")?;\nlet parsed: serde_json::Value = serde_json::from_slice(&tracker)?;\nassert!(parsed[\"installs\"].is_object(), \"corrupted install tracker\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always uninstall via `cargo uninstall`, never by hand-editing `.crates2.json`.","Back up `~/.cargo/.crates2.json` before experimentation.","If duplicates appear, remove the stale entry with `cargo uninstall`."],"tags":["cargo","panic","invariant","cargo-install","tracking","metadata","rust"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}