{"id":"16163e6180604b6e","repo":"rust-lang/cargo","slug":"just-inserted","errorCode":null,"errorMessage":"just inserted","messagePattern":"just inserted","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/ops/cargo_fix/mod.rs","lineNumber":559,"sourceCode":"    fixes\n}\n\nfn rename_target_fields_2024(target: &mut dyn toml_edit::TableLike) -> usize {\n    let mut fixes = 0;\n    fixes += rename_table(target, \"crate_type\", \"crate-type\");\n    fixes += rename_table(target, \"proc_macro\", \"proc-macro\");\n    fixes\n}\n\nfn rename_table(parent: &mut dyn toml_edit::TableLike, old: &str, new: &str) -> usize {\n    let Some(old_key) = parent.key(old).cloned() else {\n        return 0;\n    };\n\n    let project = parent.remove(old).expect(\"returned early\");\n    if !parent.contains_key(new) {\n        parent.insert(new, project);\n        let mut new_key = parent.key_mut(new).expect(\"just inserted\");\n        *new_key.dotted_decor_mut() = old_key.dotted_decor().clone();\n        *new_key.leaf_decor_mut() = old_key.leaf_decor().clone();\n    }\n    1\n}\n\nfn check_resolver_change<'gctx>(\n    ws: &Workspace<'gctx>,\n    target_data: &mut RustcTargetData<'gctx>,\n    opts: &FixOptions,\n) -> CargoResult<()> {\n    let root = ws.root_maybe();\n    match root {\n        MaybePackage::Package(root_pkg) => {\n            if root_pkg.manifest().resolve_behavior().is_some() {\n                // If explicitly specified by the user, no need to check.\n                return Ok(());\n            }","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_fix/mod.rs#L541-L577","documentation":"This panic is in rename_table() immediately after the parent.remove(old)/parent.insert(new) sequence. On line 558 it inserts the renamed key into the TOML table, then on line 559 calls parent.key_mut(new).expect(\"just inserted\") to copy decoration from the old key to the new key. The invariant is that inserting a key makes it immediately retrievable via key_mut.","triggerScenarios":"Inserting a key into a toml_edit table and then not finding it via key_mut — this would require a toml_edit internal bug where insert doesn't register the key, or the new key string is empty/whitespace and toml_edit silently rejects it while reporting success.","commonSituations":"Running cargo fix --edition on a manifest with deprecated fields; using a cargo version built against a buggy or incompatible toml_edit release; essentially unreachable in normal operation.","solutions":["Manually rename the deprecated fields in Cargo.toml before running cargo fix.","Update cargo to the latest stable release to get a compatible toml_edit version.","If embedding cargo, ensure the toml_edit version matches what cargo expects."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Same as 298 — pre-validate manifest field names before cargo fix\nlet content = std::fs::read_to_string(\"Cargo.toml\")?;\nlet doc: toml_edit::DocumentMut = content.parse()?;\n// Check for deprecated fields\nfor table_name in [\"lib\", \"bin\", \"crate_type\", \"proc_macro\"] {\n    if doc.get(table_name).is_some() && table_name.contains('_') {\n        eprintln!(\"rename `{}` to `{}`\", table_name, table_name.replace('_', \"-\"));\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use kebab-case for all Cargo.toml field names to avoid edition-migration code paths.","Manually rename deprecated fields before running cargo fix.","Keep cargo updated to get the latest toml_edit compatibility fixes."],"tags":["rust","cargo","panic","invariant","cargo-fix","toml-edit","edition-migration"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}