rust-lang/cargo · error · anyhow::Error

`{old_path}` is unsupported as of the 2024 edition; instead

Error message

`{old_path}` is unsupported as of the 2024 edition; instead use `{new_path}`
(in the `{name}` {kind})

What it means

Thrown by `deprecated_underscore` at src/workspace/parser/mod.rs:2917. Several manifest keys historically accepted an underscore spelling (`dev_dependencies`, `build_dependencies`, and target-section equivalents). In edition 2024 and later the underscore form is a hard error (`old.is_some() && Edition::Edition2024 <= edition`); cargo reports the old (underscore) path and the required hyphenated replacement, scoped to the package or platform target where it appeared.

Source

Thrown at src/workspace/parser/mod.rs:2917

    if let Err(err) = gctx.shell().print_report(&[group], true) {
        return err.into();
    }
    return AlreadyPrintedError::new(e.into()).into();
}

/// Warn about paths that have been deprecated and may conflict.
fn deprecated_underscore<T>(
    old: &Option<T>,
    new: &Option<T>,
    new_path: &str,
    name: &str,
    kind: &str,
    edition: Edition,
    warnings: &mut Vec<String>,
) -> CargoResult<()> {
    let old_path = new_path.replace("-", "_");
    if old.is_some() && Edition::Edition2024 <= edition {
        anyhow::bail!(
            "`{old_path}` is unsupported as of the 2024 edition; instead use `{new_path}`\n(in the `{name}` {kind})"
        );
    } else if old.is_some() && new.is_some() {
        warnings.push(format!(
            "`{old_path}` is redundant with `{new_path}`, preferring `{new_path}` in the `{name}` {kind}"
        ))
    } else if old.is_some() {
        warnings.push(format!(
            "`{old_path}` is deprecated in favor of `{new_path}` and will not work in the 2024 edition\n(in the `{name}` {kind})"
        ))
    }
    Ok(())
}

fn warn_on_unused(unused: &BTreeSet<String>, warnings: &mut Vec<String>) {
    use std::fmt::Write as _;

    for key in unused {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Rename every underscored section to its hyphenated form: `[dev_dependencies]` → `[dev-dependencies]`, `[build_dependencies]` → `[build-dependencies]` (also inside `[target.*]`).
  2. Run `cargo check`/`cargo fmt` after renaming to catch any remaining instances.

Example fix

# before (edition 2024)
[dev_dependencies]
serde = "1"
# after
[dev-dependencies]
serde = "1"
Defensive patterns

Strategy: validation

Validate before calling

const UNDERSCORED: &[&str] = &["dev_dependencies","build_dependencies"];
for key in UNDERSCORED {
    if doc.as_table().contains_key(*key) {
        return Err(format!("{key} unsupported in edition 2024; use the hyphen form"));
    }
}
// also check [target.*] sub-tables

Prevention

When it happens

Trigger: A Cargo.toml on edition 2024 that uses `[dev_dependencies]` or `[build_dependencies]` (underscore) instead of `[dev-dependencies]` / `[build-dependencies]` (hyphen), including under `[target.<cfg>]`.

Common situations: Upgrading an older crate to edition 2024; manifests written before the hyphen form was canonical; bulk find-replace that reintroduced underscores.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/224530a4f5b14235.json. Report an issue: GitHub.