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

package ID specification{plural} did not match any direct de

Error message

package ID specification{plural} did not match any direct dependencies that could be upgraded

What it means

During breaking-dependency upgrades (update_breaking_deps), each package ID spec given must match a direct registry dependency of some workspace member. Any spec left in remaining_specs after walking all members is unmatched, so cargo_update.rs:315 bails, optionally noting specs that exist only as transitive deps (which --breaking cannot upgrade).

Source

Thrown at src/ops/cargo_update.rs:315

                        && spec
                            .version()
                            .map_or(true, |v| dep.version_req().matches(&v))
                })
            });

            // Track transitive specs for notes at the end
            if in_lockfile && !matches_direct_dep {
                transitive_specs.push(spec);
            }
        }

        for spec in transitive_specs {
            error_msg.push_str(&format!(
                "\nnote: `{spec}` exists as a transitive dependency but those are not available for upgrading through `--breaking`"
            ));
        }

        anyhow::bail!("{error_msg}");
    }

    Ok(upgrades)
}

fn upgrade_dependency(
    gctx: &GlobalContext,
    to_update: &Vec<PackageIdSpec>,
    registry: &mut PackageRegistry<'_>,
    upgrades: &mut UpgradeMap,
    upgrade_messages: &mut HashSet<String>,
    remaining_specs: &mut IndexSet<PackageIdSpec>,
    dependency: Dependency,
) -> CargoResult<Dependency> {
    let name = dependency.package_name();
    let renamed_to = dependency.name_in_toml();

    if name != renamed_to {

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Verify the spec names a direct registry dependency of a workspace member (check Cargo.toml).
  2. For transitive deps, upgrade the direct dependency that pulls them in, or drop --breaking and use `cargo update -p <transitive>`.
  3. Check for renames in Cargo.toml and use the name_in_toml / correct package name.

Example fix

# before
$ cargo update --breaking -p transitive-only-crate
error: package ID specification did not match any direct dependencies ...
  note: `transitive-only-crate` exists as a transitive dependency ...

# after - upgrade the direct dep, or drop --breaking
$ cargo update --breaking -p my-direct-dep
#   or, for a transitive dep without --breaking:
$ cargo update -p transitive-only-crate
Defensive patterns

Strategy: validation

Validate before calling

# Confirm each spec is a direct registry dependency before --breaking:
for spec in "$@"; do
  name="${spec%%:*}"
  if ! cargo tree --edges normal --depth 1 2>/dev/null | grep -q "$name"; then
    echo "$name is not a direct dependency" >&2; exit 1
  fi
done
cargo update --breaking "$@"

Prevention

When it happens

Trigger: `cargo update --breaking <spec>` (or passing specs that resolve to zero direct deps) where spec is misspelled, refers to a transitive-only dep, or is a path/git dependency (only registry deps are upgradable).

Common situations: Trying to upgrade a transitive dep directly via --breaking; typo in the package name; dep was renamed; dep is a workspace/path dep not on a registry.

Related errors


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