{"record":{"id":"2fc80206c0d9f133","repo":"rust-lang/cargo","slug":"package-id-specification-did-not-match-any-pa","errorCode":null,"errorMessage":"package ID specification `{}` did not match any packages{}","messagePattern":"package ID specification `(.+?)` did not match any packages(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_clean.rs","lineNumber":266,"sourceCode":"        }\n        if spec.url().is_some() {\n            clean_ctx.gctx.shell().warn(&format!(\n                \"url qualifier in `-p {}` ignored, \\\n                cleaning all versions of `{}` found\",\n                spec_str,\n                spec.name()\n            ))?;\n        }\n        let matches: Vec<_> = resolve.iter().filter(|id| spec.matches(*id)).collect();\n        if matches.is_empty() {\n            let mut suggestion = String::new();\n            suggestion.push_str(&edit_distance::closest_msg(\n                &spec.name(),\n                resolve.iter(),\n                |id| id.name().as_str(),\n                \"package\",\n            ));\n            anyhow::bail!(\n                \"package ID specification `{}` did not match any packages{}\",\n                spec,\n                suggestion\n            );\n        }\n        pkg_ids.extend(matches);\n    }\n    let packages = pkg_set.get_many(pkg_ids)?;\n\n    clean_ctx.progress = Box::new(CleaningPackagesBar::new(clean_ctx.gctx, packages.len()));\n    let mut dirs_to_clean = DirectoriesToClean::default();\n\n    if clean_ctx.gctx.cli_unstable().build_dir_new_layout {\n        for pkg in packages {\n            clean_ctx.progress.on_cleaning_package(&pkg.name())?;\n\n            // Remove intermediate artifacts\n            for (_compile_kind, layout) in &layouts_with_host {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/cargo_clean.rs#L248-L284","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\ncargo clean -p mycrate@1.0.0\n# after (find resolved version)\ncargo metadata --format-version 1 | jq '.packages[] | {name,version}'","handlingStrategy":"validation","validationCode":"// Resolve valid package specs from metadata before running cargo clean -p.\n// cargo metadata --format-version 1 -> JSON; collect name@version strings.\nfn known_specs(meta_json: &str) -> Vec<String> { /* parse packages[].name@version */ vec![] }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cargo-clean","package-spec","dependency-resolution","user-input"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}