{"id":"3d15e688be15abaa","repo":"rust-lang/cargo","slug":"must-have-the-unit","errorCode":null,"errorMessage":"must have the unit","messagePattern":"must have the unit","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_report/rebuilds.rs","lineNumber":321,"sourceCode":"        DEFAULT_DISPLAY_LIMIT.min(root_rebuilds.len())\n    };\n    let truncated_count = root_rebuilds.len().saturating_sub(display_limit);\n\n    if truncated_count > 0 {\n        let count = root_rebuilds.len();\n        writeln!(\n            stderr,\n            \"{header}Root rebuilds:{header:#} (top {display_limit} of {count} by impact)\",\n        )?;\n    } else {\n        writeln!(stderr, \"{header}Root rebuilds:{header:#}\",)?;\n    }\n\n    for (idx, root_rebuild) in root_rebuilds.iter().take(display_limit).enumerate() {\n        let unit_desc = units\n            .get(&root_rebuild.unit_index)\n            .map(unit_description)\n            .expect(\"must have the unit\");\n\n        let reason_str = format_dirty_reason(&root_rebuild.reason, &units, ws_root);\n\n        writeln!(\n            stderr,\n            \"  {subheader}{idx}. {unit_desc}:{subheader:#} {reason_str}\",\n        )?;\n\n        if root_rebuild.affected_units.is_empty() {\n            writeln!(stderr, \"     impact: no cascading rebuilds\")?;\n        } else {\n            let count = root_rebuild.affected_units.len();\n            let plural = plural(count);\n            writeln!(\n                stderr,\n                \"     impact: {count} dependent unit{plural} rebuilt\"\n            )?;\n","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_report/rebuilds.rs#L303-L339","documentation":"Invariant in `cargo report rebuilds`. The code iterates `root_rebuilds` and looks each `unit_index` up in a `units` map via `units.get(&root_rebuild.unit_index).map(unit_description).expect(\"must have the unit\")`. Every unit referenced by a rebuild entry must already exist in the units map built earlier in the report.","triggerScenarios":"Fires only if a `RootRebuild`'s `unit_index` is not present in the `units` map that `cargo report rebuilds` constructed from the build graph. This indicates the rebuild-analysis index and the unit map got out of sync.","commonSituations":"Cargo bug in the `cargo report` (future-build-report) experimental subcommand; mismatched index after a partial/aborted build-graph build; running an unreleased `cargo report` against a stale build cache.","solutions":["Clear cargo's build cache (`cargo clean` and remove `target/`) and re-run the build + `cargo report rebuilds`.","Report a cargo bug with the `cargo report rebuilds -vv` output and the workspace manifest.","Update cargo — this is part of an evolving experimental feature and fixes land frequently."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before calling cargo report rebuilds, ensure every rebuild unit exists in the unit map.\nfor r in &root_rebuilds {\n    if !units.contains_key(&r.unit_index) {\n        return Err(anyhow!(\"rebuild references unknown unit {}\", r.unit_index));\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `cargo clean` before `cargo report rebuilds` to avoid stale build-graph state.","Keep cargo updated — `cargo report` is an evolving experimental feature."],"tags":["cargo","panic","invariant","cargo-report","rebuilds","build-graph","rust"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}