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
- Ensure the dependency item is a TOML string (simple version) or a TOML table (detailed spec).
- If building the manifest programmatically, validate the toml_edit::Item type before assignment.
- 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
- Before inserting a toml_edit::Item into a dependencies table, assert it is a string or table.
- When programmatically editing manifests, use toml_edit::Item::value to construct valid entries.
- Validate manifest structure with `cargo metadata` after generation.
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
- dependency ( ) specified without providing a local path…
- ` .workspace = false` is unsupported
- Use of `default_features` in
- can only edit absolute paths, got
- dependency ( ) specified without providing a local path…
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.)
///
/// # PanicView on GitHub (pinned to eb98b54bc9)