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

dependency ({key}) specified without providing a local path,

Error message

dependency ({key}) specified without providing a local path, Git repository, version, or workspace dependency to use

What it means

Thrown by `Dependency::from_toml` (editor) at src/workspace/editor/dependency.rs:323 when a dependency table provides none of the recognized source keys (`git`, `path`, `version`, or `workspace`). Without one of these cargo cannot determine where to fetch the dependency, so parsing aborts.

Source

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

                        })?);
                    }
                    src.into()
                } else if let Some(version) = table.get("version") {
                    let src = RegistrySource::new(version.as_str().ok_or_else(|| {
                        invalid_type(key, "version", version.type_name(), "string")
                    })?);
                    src.into()
                } else if let Some(workspace) = table.get("workspace") {
                    let workspace_bool = workspace.as_bool().ok_or_else(|| {
                        invalid_type(key, "workspace", workspace.type_name(), "bool")
                    })?;
                    if !workspace_bool {
                        anyhow::bail!("`{key}.workspace = false` is unsupported")
                    }
                    let src = WorkspaceSource::new();
                    src.into()
                } else {
                    anyhow::bail!(
                        "dependency ({key}) specified without \
                        providing a local path, Git repository, version, or \
                        workspace dependency to use"
                    );
                };
            let registry = if let Some(value) = table.get("registry") {
                Some(
                    value
                        .as_str()
                        .ok_or_else(|| invalid_type(key, "registry", value.type_name(), "string"))?
                        .to_owned(),
                )
            } else {
                None
            };

            let default_features = table.get("default-features").and_then(|v| v.as_bool());
            if table.contains_key("default_features") {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Add a source: a version `foo = { version = "1.0", optional = true }`, a path, a git URL, or `workspace = true`.
  2. If you only wanted metadata, the dependency still needs a source — supply the registry version.
  3. Re-run `cargo add foo@1.0` to regenerate a well-formed entry.

Example fix

# before
foo = { optional = true }
# after
foo = { version = "1.0", optional = true }
Defensive patterns

Strategy: validation

Validate before calling

const SOURCES: [&str; 4] = ["git", "path", "version", "workspace"];
for (k, item) in deps {
    if let Some(t) = item.as_table_like() {
        if !SOURCES.iter().any(|s| t.contains_key(s)) {
            eprintln!("dependency {k} has no source key");
        }
    }
}

Prevention

When it happens

Trigger: An entry like `foo = { optional = true }`, `foo = { features = ["a"] }`, or `foo = {}` — a table with only metadata keys and no source. Reached only when all four source branches (`git`/`path`/`version`/`workspace`) are absent.

Common situations: Forgetting the version after adding optional/features; partial edits by `cargo add` interrupted mid-write; migrating a dependency and deleting the version line by accident.

Related errors


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