rust-lang/cargo · error

Unrecognized` dependency entry format for

Error message

Unrecognized` dependency entry format for `{key}

What it means

Thrown by the manifest editor dependency parser when the dependency item is neither a TOML string nor a table-like value. The from_toml method first tries item.as_str() then item.as_table_like(); if both return None it reaches the final else branch. Note the message itself contains a stray backtick ('Unrecognized`') which is a bug in the format string.

Solutions

  1. Ensure the dependency item is a TOML string (simple version) or a TOML table (detailed spec).
  2. If building the manifest programmatically, validate the toml_edit::Item type before assignment.
  3. Inspect the raw Cargo.toml at the named key and replace the invalid value with a proper dependency spec.

Example fix

# before (invalid)
[dependencies]
serde = 1

# after
[dependencies]
serde = "1"
Defensive patterns

Strategy: type-guard

Validate before calling

fn dependency_item_is_valid(item: &toml_edit::Item) -> bool {
    item.is_str() || item.is_table_like()
}

Type guard

fn is_valid_dependency_item(item: &toml_edit::Item) -> bool {
    item.as_str().is_some() || item.as_table_like().is_some()
}

Prevention

When it happens

Trigger: Calling Dependency::from_toml where the toml_edit::Item is an integer, float, boolean, array, or an invalid/non-table/non-string node. This is structurally invalid for a dependency entry which must be either a version string or a detailed table.

Common situations: A programmatic manifest edit inserts a wrong toml_edit::Item type into a dependency slot. Corrupt or hand-written TOML where a dependency value is a bare number or boolean. A serialization bug that writes a scalar where a table or string was expected.

Related errors


AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11). Data as JSON: /api/errors/242f0d0b550f54d6. Report an issue: GitHub.

Appendix: 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
    /// explicitly set, an `InlineTable` is returned in any case.)
    ///
    /// # Panic

View on GitHub (pinned to eb98b54bc9)