rust-lang/cargo · error · anyhow::Error
Deprecated dependency sections are unsupported
Error message
Deprecated dependency sections are unsupported: {} What it means
Thrown by the cargo add operation when the target manifest contains deprecated dependency section syntax that cargo add cannot safely modify. The get_legacy_sections() check identifies old-style sections that predate current manifest conventions.
Solutions
- Run `cargo fix --edition` or manually update the manifest to use modern dependency section syntax
- Inspect the manifest for sections listed in the error and convert them to standard [dependencies] table format
- Use `cargo migrate` or equivalent tooling to modernize the manifest before running cargo add
Defensive patterns
Strategy: validation
Validate before calling
// Check for legacy sections before running cargo add
fn check_legacy_sections(manifest_path: &Path) -> Result<(), String> {
let content = std::fs::read_to_string(manifest_path).map_err(|e| e.to_string())?;
let toml_val: toml::Value = toml::from_str(&content).map_err(|e| e.to_string())?;
// Check for known deprecated section patterns
if let Some(table) = toml_val.as_table() {
for key in table.keys() {
if key.contains("_dependencies") && !is_standard_dep_section(key) {
return Err(format!("deprecated section found: {key}"));
}
}
}
Ok(())
} Prevention
- Run cargo fix --edition to modernize old manifests before using cargo add
- Keep manifests in modern syntax by upgrading editions proactively
- Avoid manually creating non-standard dependency section names
When it happens
Trigger: Running `cargo add <dep>` against a Cargo.toml that contains deprecated dependency section formats detected by LocalManifest::get_legacy_sections().
Common situations: Very old manifests with pre-2018 edition syntax. Manually edited manifests with non-standard section names. Manifests migrated through tooling that left legacy artifacts.
Related errors
- the manifest file needs to be updated but was passed to…
- all versions of crate
- can only edit absolute paths, got
- can't find library ` `, rename file to `src/lib.rs` or…
- cannot add ` ` as a dependency to itself
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/7f982abfdb26bffc.
Report an issue: GitHub.
Appendix: source
Thrown at src/ops/cargo_add/mod.rs:88
/// Whether the minimum supported Rust version should be considered during resolution
pub honor_rust_version: Option<bool>,
}
/// Add dependencies to a manifest
pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<()> {
let dep_table = options
.section
.to_table()
.into_iter()
.map(String::from)
.collect::<Vec<_>>();
let manifest_path = options.spec.manifest_path().to_path_buf();
let mut manifest = LocalManifest::try_new(&manifest_path)?;
let original_raw_manifest = manifest.to_string();
let legacy = manifest.get_legacy_sections();
if !legacy.is_empty() {
anyhow::bail!(
"Deprecated dependency sections are unsupported: {}",
legacy.join(", ")
);
}
let mut registry = workspace.package_registry()?;
let deps = {
let _lock = options
.gctx
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
registry.lock_patches();
options
.dependencies
.iter()
.map(|raw| {
resolve_dependency(
&manifest,View on GitHub (pinned to 98a09e7e7d)