{"id":"fba2214a389a5008","repo":"rust-lang/cargo","slug":"manifest-validated","errorCode":null,"errorMessage":"manifest validated","messagePattern":"manifest validated","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":259,"sourceCode":"\n        print_dep_table_msg(&mut options.gctx.shell(), &dep)?;\n\n        manifest.insert_into_table(\n            &dep_table,\n            &dep,\n            workspace.gctx(),\n            workspace.root(),\n            options.spec.manifest().unstable_features(),\n        )?;\n        if dep.optional == Some(true) {\n            let is_namespaced_features_supported =\n                check_rust_version_for_optional_dependency(options.spec.rust_version())?;\n            if is_namespaced_features_supported {\n                let dep_key = dep.toml_key();\n                if !manifest.is_explicit_dep_activation(dep_key) {\n                    let table = manifest\n                        .get_table_mut(&[String::from(\"features\")])\n                        .expect(\"manifest validated\");\n                    let dep_name = dep.rename.as_deref().unwrap_or(&dep.name);\n                    let new_feature: toml_edit::Value =\n                        [format!(\"dep:{dep_name}\")].iter().collect();\n                    table[dep_key] = toml_edit::value(new_feature);\n                    options\n                        .gctx\n                        .shell()\n                        .status(\"Adding\", format!(\"feature `{dep_key}`\"))?;\n                }\n            }\n        }\n        manifest.gc_dep(dep.toml_key());\n    }\n\n    if was_sorted {\n        if let Some(table) = manifest\n            .get_table_mut(&dep_table)\n            .and_then(TomlItem::as_table_like_mut)","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_add/mod.rs#L241-L277","documentation":"This panic fires in the cargo add code path when adding an optional dependency. After inserting the dep into the manifest's dependency table, cargo checks if the [features] table already has explicit dep: activation and, if not, tries to get the [features] table mutably via get_table_mut(&[String::from(\"features\")]).expect(\"manifest validated\"). The invariant is that the manifest was earlier validated to support namespaced features and have or allow a [features] table.","triggerScenarios":"Running cargo add --optional <crate> on a manifest that passed the earlier validation check (is_namespaced_features_supported) but whose [features] table cannot be retrieved — e.g., the manifest has a [features] key that is not a table (set to a string or array), or the manifest was mutated in a way that removed the table between validation and this call.","commonSituations":"A Cargo.toml where [features] is misused as a non-table value; a manifest with inconsistent structure after partial edits; running cargo add on a manifest that has [features] defined as an inline value.","solutions":["Manually inspect Cargo.toml and ensure [features] is a proper TOML table or absent (not a scalar/array).","Remove the --optional flag if you don't need optional dependency activation features.","Fix the manifest to valid structure and re-run cargo add."],"exampleFix":"# before (broken — features as scalar)\nfeatures = \"default\"\n[dependencies]\n# after\n[features]\ndefault = []\n[dependencies]","handlingStrategy":"validation","validationCode":"// Before running cargo add --optional, check [features] is a table\nlet manifest_str = std::fs::read_to_string(\"Cargo.toml\")?;\nlet doc: toml_edit::DocumentMut = manifest_str.parse()?;\nif let Some(features) = doc.get(\"features\") {\n    if !features.is_table() {\n        return Err(\"[features] must be a TOML table\".into());\n    }\n}","typeGuard":"fn features_table_is_valid(doc: &toml_edit::DocumentMut) -> bool {\n    doc.get(\"features\").map_or(true, |f| f.is_table())\n}","tryCatchPattern":null,"preventionTips":["Ensure [features] in Cargo.toml is always a proper TOML table, never a scalar or array.","Run cargo add --optional only on manifests with valid structure.","Validate Cargo.toml with cargo check or toml lint before cargo add."],"tags":["rust","cargo","panic","invariant","cargo-add","features","manifest"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}