rust-lang/cargo · error · anyhow::Error
package ID specification
Error message
package ID specification `{}` did not match any packages{} What it means
Thrown by cargo_clean when a package ID spec (the -p argument) matched zero package IDs in the resolved dependency graph. The error appends an edit-distance suggestion, so it fires after normal resolution succeeded but the user-supplied spec named something that is not in the graph.
Solutions
- Apply the closest-match suggestion cargo prints after the error (it comes from edit-distance matching over resolved package names).
- Retry with a bare name, dropping version/origin qualifiers: `cargo clean -p mycrate`.
- Find the exact resolved name and version: `cargo metadata --format-version 1 | jq -r '.packages[] | "\(.name)@\(.version)"'`, then clean with `cargo clean -p name@resolved_version`.
- If the spec pins a version that no longer resolves (e.g. after Cargo.toml changes), run `cargo update` or adjust the spec to the version in the lockfile.
Example fix
# before
cargo clean -p mycrate@1.0.0
# after (find resolved version)
cargo metadata --format-version 1 | jq '.packages[] | {name,version}' Defensive patterns
Strategy: validation
Validate before calling
// Resolve valid package specs from metadata before running cargo clean -p.
// cargo metadata --format-version 1 -> JSON; collect name@version strings.
fn known_specs(meta_json: &str) -> Vec<String> { /* parse packages[].name@version */ vec![] } Prevention
- Generate -p arguments from `cargo metadata` rather than hard-coding versions.
- Use bare names (`-p name`) where possible to avoid version drift.
- Apply the edit-distance suggestion when a spec misses.
When it happens
Trigger: Running `cargo clean -p <spec>` where <spec> is a typo, names a package not in the workspace/deps, or uses an origin/version that does not match any resolved PackageId (e.g. wrong version after an update).
Common situations: Typos in package names in scripts; renaming a crate but not updating the clean command; cleaning a dependency that was removed from Cargo.toml; version mismatch after cargo update changed the resolved version.
Related errors
- package(s) ` ` not found in workspace
- artifact-dir was not locked during clean
- can't checkout from ' ': you are in the offline mode ( )
- --exclude can only be used together with --workspace
- extra arguments to ` ` can only be passed to one target…
AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11).
Data as JSON: /api/errors/2fc80206c0d9f133.
Report an issue: GitHub.
Appendix: source
Thrown at src/ops/cargo_clean.rs:266
}
if spec.url().is_some() {
clean_ctx.gctx.shell().warn(&format!(
"url qualifier in `-p {}` ignored, \
cleaning all versions of `{}` found",
spec_str,
spec.name()
))?;
}
let matches: Vec<_> = resolve.iter().filter(|id| spec.matches(*id)).collect();
if matches.is_empty() {
let mut suggestion = String::new();
suggestion.push_str(&edit_distance::closest_msg(
&spec.name(),
resolve.iter(),
|id| id.name().as_str(),
"package",
));
anyhow::bail!(
"package ID specification `{}` did not match any packages{}",
spec,
suggestion
);
}
pkg_ids.extend(matches);
}
let packages = pkg_set.get_many(pkg_ids)?;
clean_ctx.progress = Box::new(CleaningPackagesBar::new(clean_ctx.gctx, packages.len()));
let mut dirs_to_clean = DirectoriesToClean::default();
if clean_ctx.gctx.cli_unstable().build_dir_new_layout {
for pkg in packages {
clean_ctx.progress.on_cleaning_package(&pkg.name())?;
// Remove intermediate artifacts
for (_compile_kind, layout) in &layouts_with_host {View on GitHub (pinned to 98a09e7e7d)