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

Unrecognized` dependency entry format for `{key}`

Error message

Unrecognized` dependency entry format for `{key}`

What it means

Thrown by `Dependency::from_toml` (editor) at src/workspace/editor/dependency.rs:380 — the final `else` branch of the parser. It fires when the TOML value for a dependency key is neither a plain version string nor a table-like item (e.g. it is an integer, float, bool, array, or datetime). A dependency must be `name = "version"` or `name = { ... }`.

Source

Thrown at src/workspace/editor/dependency.rs:380

            };

            let optional = table.get("optional").and_then(|v| v.as_bool());
            let public = table.get("public").and_then(|v| v.as_bool());

            let dep = Self {
                name,
                optional,
                public,
                features,
                default_features,
                inherited_features: None,
                source: Some(source),
                registry,
                rename,
            };
            Ok(dep)
        } else {
            anyhow::bail!("Unrecognized` dependency entry format for `{key}");
        }
    }

    /// Get the dependency name as defined in the manifest,
    /// that is, either the alias (rename field if Some),
    /// or the official package name (name field).
    pub fn toml_key(&self) -> &str {
        self.rename().unwrap_or(&self.name)
    }

    /// Convert dependency to TOML.
    ///
    /// Returns a tuple with the dependency's name and either the version as a
    /// `String` or the path/git repository as an `InlineTable`.
    /// (If the dependency is set as `optional` or `default-features` is set to
    /// `false`, an `InlineTable` is returned in any case.)
    ///
    /// # Panic

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Quote the version: `foo = "1.0"`.
  2. If you need options, use a table: `foo = { version = "1.0", optional = true }`.
  3. Validate the manifest with `toml-edit`/`cargo check` after editing to catch the type mismatch early.

Example fix

# before
foo = 1.0
# after
foo = "1.0"
Defensive patterns

Strategy: type-guard

Type guard

fn is_valid_dep_item(item: &toml_edit::Item) -> bool {
    item.as_str().is_some() || item.as_table_like().is_some()
}
// assert is_valid_dep_item(&doc["dependencies"]["foo"]) before parsing

Prevention

When it happens

Trigger: Entries such as `foo = 1` (bare integer), `foo = true`, `foo = ["1.0"]`, or `foo = 1.0`. The `if let Some(version) = item.as_str()` and `else if let Some(table) = item.as_table_like()` branches both fail, dropping into the catch-all.

Common situations: Omitting quotes around a version (`foo = 1.0` instead of `foo = "1.0"`); malformed YAML-to-TOML conversion; LLM-generated manifests.

Related errors


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