rust-lang/cargo · warning
just inserted
Error message
just inserted
What it means
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.
Source
Thrown at src/ops/cargo_fix/mod.rs:559
fixes
}
fn rename_target_fields_2024(target: &mut dyn toml_edit::TableLike) -> usize {
let mut fixes = 0;
fixes += rename_table(target, "crate_type", "crate-type");
fixes += rename_table(target, "proc_macro", "proc-macro");
fixes
}
fn rename_table(parent: &mut dyn toml_edit::TableLike, old: &str, new: &str) -> usize {
let Some(old_key) = parent.key(old).cloned() else {
return 0;
};
let project = parent.remove(old).expect("returned early");
if !parent.contains_key(new) {
parent.insert(new, project);
let mut new_key = parent.key_mut(new).expect("just inserted");
*new_key.dotted_decor_mut() = old_key.dotted_decor().clone();
*new_key.leaf_decor_mut() = old_key.leaf_decor().clone();
}
1
}
fn check_resolver_change<'gctx>(
ws: &Workspace<'gctx>,
target_data: &mut RustcTargetData<'gctx>,
opts: &FixOptions,
) -> CargoResult<()> {
let root = ws.root_maybe();
match root {
MaybePackage::Package(root_pkg) => {
if root_pkg.manifest().resolve_behavior().is_some() {
// If explicitly specified by the user, no need to check.
return Ok(());
}View on GitHub (pinned to 0e07a15537)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Same as 298 — pre-validate manifest field names before cargo fix
let content = std::fs::read_to_string("Cargo.toml")?;
let doc: toml_edit::DocumentMut = content.parse()?;
// Check for deprecated fields
for table_name in ["lib", "bin", "crate_type", "proc_macro"] {
if doc.get(table_name).is_some() && table_name.contains('_') {
eprintln!("rename `{}` to `{}`", table_name, table_name.replace('_', "-"));
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- returned early
- able to invoke rustc
- bin is an array of tables
- package is a table
- artifact-dir was not locked
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/16163e6180604b6e.json.
Report an issue: GitHub.