{"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":256,"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":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_clean.rs#L238-L274","documentation":"When `cargo clean -p <spec>` is given, cargo resolves the spec against the dependency graph; if no package matches, it bails at cargo_clean.rs:256. The message includes the parsed spec and, when possible, an edit-distance suggestion for a similarly-named package. This mirrors cargo's general package-spec resolution semantics.","triggerScenarios":"`cargo clean -p nonexistent`, or `-p` with a spec whose name/version/target does not match anything in the resolved workspace graph. The `matches` Vec from filtering `resolve.iter()` is empty.","commonSituations":"Typo in the package name, cleaning a dependency that is not part of the current lockfile, or specifying a version qualifier that does not match any resolved package (version/url qualifiers are warned but still must match by name).","solutions":["Use the suggested name from the error (edit-distance hint) if one is offered.","List available packages with `cargo metadata` (or `cargo clean -p <TAB>` completion) and copy the exact name.","Drop version/url qualifiers from `-p` — they are ignored for cleaning and a bare name must still match."],"exampleFix":"# before\ncargo clean -p serd\n\n# after\ncargo clean -p serde","handlingStrategy":"validation","validationCode":"// Resolve -p specs against cargo metadata before cleaning.\nfn resolve_spec(meta: &cargo_metadata::Metadata, spec: &str) -> bool {\n    meta.packages.iter().any(|p| p.name == spec || spec.starts_with(&format!(\"{}@\", p.name)))\n}\n// let meta = cargo_metadata::MetadataCommand::new().exec()?;\n// for s in &specs { assert!(resolve_spec(&meta, s), \"unknown package: {s}\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate `-p` specs from `cargo metadata` rather than typing names by hand.","Strip version/url qualifiers from clean specs (they are ignored anyway).","Use shell completion for package names to avoid typos."],"tags":["cargo-clean","package-spec","not-found","typo"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}