{"id":"7f982abfdb26bffc","repo":"rust-lang/cargo","slug":"deprecated-dependency-sections-are-unsupported","errorCode":null,"errorMessage":"Deprecated dependency sections are unsupported: {}","messagePattern":"Deprecated dependency sections are unsupported: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":86,"sourceCode":"    /// Whether the minimum supported Rust version should be considered during resolution\n    pub honor_rust_version: Option<bool>,\n}\n\n/// Add dependencies to a manifest\npub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<()> {\n    let dep_table = options\n        .section\n        .to_table()\n        .into_iter()\n        .map(String::from)\n        .collect::<Vec<_>>();\n\n    let manifest_path = options.spec.manifest_path().to_path_buf();\n    let mut manifest = LocalManifest::try_new(&manifest_path)?;\n    let original_raw_manifest = manifest.to_string();\n    let legacy = manifest.get_legacy_sections();\n    if !legacy.is_empty() {\n        anyhow::bail!(\n            \"Deprecated dependency sections are unsupported: {}\",\n            legacy.join(\", \")\n        );\n    }\n\n    let mut registry = workspace.package_registry()?;\n\n    let deps = {\n        let _lock = options\n            .gctx\n            .acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;\n        registry.lock_patches();\n        options\n            .dependencies\n            .iter()\n            .map(|raw| {\n                resolve_dependency(\n                    &manifest,","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_add/mod.rs#L68-L104","documentation":"Thrown by `cargo add` when the target manifest still uses the deprecated dependency table names `dev_dependencies` / `build_dependencies` (or `target.<t>.dev_dependencies` / `target.<t>.build_dependencies`). cargo-add cannot reliably mutate these legacy sections, so it refuses to proceed and asks the user to migrate them to the hyphenated forms (`dev-dependencies`, `build-dependencies`). The check runs unconditionally in `add()` right after the manifest is loaded via `LocalManifest::try_new`, before any dependency resolution.","triggerScenarios":"A `Cargo.toml` containing `[dev_dependencies]` or `[build_dependencies]` (underscores) and then invoking `cargo add <dep>` (or `cargo add <dep> --dev`). `get_legacy_sections()` returns any matching top-level or `target.*` keys, and if the resulting list is non-empty the function bails with the section names joined by \", \".","commonSituations":"Older crates created before the hyphen convention was enforced, manifests authored by hand, or manifests generated by tooling that emitted underscores. The error is environmental (the file being edited), not a bug in the caller's dependency choice.","solutions":["Open the named manifest and rename every `[dev_dependencies]` to `[dev-dependencies]` and `[build_dependencies]` to `[build-dependencies]`, including any under `[target.'cfg(...)']`.","Re-run `cargo add` once the section names are hyphenated; `get_legacy_sections()` will now return an empty Vec and the bail is skipped.","Run `cargo fix --edition` or a TOML linter that normalizes dependency table names to prevent recurrence."],"exampleFix":"// before (Cargo.toml)\n[dev_dependencies]\nserde_json = \"1\"\n\n// after\n[dev-dependencies]\nserde_json = \"1\"","handlingStrategy":"validation","validationCode":"// Before calling ops::add, ensure the manifest has no legacy sections.\nuse cargo_util_schemas::manifest;\n\nfn has_legacy_sections(text: &str) -> Result<(), Vec<String>> {\n    let doc: toml_edit::ImDocument<_> = toml_edit::ImDocument::parse(text).unwrap();\n    let mut bad = Vec::new();\n    for k in [\"dev_dependencies\", \"build_dependencies\"] {\n        if doc.as_table().contains_key(k) { bad.push(k.to_string()); }\n    }\n    if bad.is_empty() { Ok(()) } else { Err(bad) }\n}\n\n// let manifest_text = std::fs::read_to_string(&manifest_path)?;\n// has_legacy_sections(&manifest_text).map_err(|bad| anyhow::anyhow!(\"rename to hyphenated: {bad:?}\"))?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a pre-commit TOML linter that rejects underscore dependency section names.","Use `cargo fix --edition` after scaffolding to normalize manifest keys.","In CI, add a grep check: fail if `Cargo.toml` contains `[dev_dependencies]` or `[build_dependencies]`."],"tags":["cargo-add","manifest","deprecation","toml"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}