rust-lang/cargo · error
"--package <SPEC>" requires a SPEC format value. Run `cargo
Error message
"--package <SPEC>" requires a SPEC format value. Run `cargo help pkgid` for more information about SPEC format.
What it means
In `cargo uninstall` (uninstall.rs:37-43), `is_present_with_zero_values("package")` is true when the user passes `--package` (or `-p`) with no value. Because `--package <SPEC>` requires a SPEC, Cargo bails and points to `cargo help pkgid` for the accepted spec grammar.
Source
Thrown at src/bin/cargo/commands/uninstall.rs:38
.arg_silent_suggestion()
.arg_package_spec_simple(
"Package to uninstall",
ArgValueCandidates::new(get_installed_package_candidates),
)
.arg(
multi_opt("bin", "NAME", "Only uninstall the binary NAME")
.help_heading(heading::TARGET_SELECTION),
)
.after_help(color_print::cstr!(
"Run `<bright-cyan,bold>cargo help uninstall</>` for more detailed information.\n"
))
}
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let root = args.get_one::<String>("root").map(String::as_str);
if args.is_present_with_zero_values("package") {
return Err(anyhow::anyhow!(
"\"--package <SPEC>\" requires a SPEC format value.\n\
Run `cargo help pkgid` for more information about SPEC format."
)
.into());
}
let specs = args
.get_many::<String>("spec")
.unwrap_or_else(|| args.get_many::<String>("package").unwrap_or_default())
.map(String::as_str)
.collect();
ops::uninstall(root, specs, &values(args, "bin"), gctx)?;
Ok(())
}
fn get_installed_crates() -> Vec<clap_complete::CompletionCandidate> {
get_installed_crates_().unwrap_or_default()
}View on GitHub (pinned to 0e07a15537)
Solutions
- Provide a SPEC value: `cargo uninstall -p my-crate`.
- Use a full spec if needed: `cargo uninstall -p my-crate@1.2.3` (see `cargo help pkgid`).
- Drop `-p` entirely to uninstall by positional name: `cargo uninstall my-crate`.
Example fix
// before $ cargo uninstall -p error: "--package <SPEC>" requires a SPEC format value. // after $ cargo uninstall -p my-crate
Defensive patterns
Strategy: validation
Validate before calling
if package_flag_present && package_value.is_none() {
return Err("--package requires a SPEC; see `cargo help pkgid`");
} Type guard
fn has_package_spec(p: Option<&str>) -> bool {
p.map(|s| !s.trim().is_empty()).unwrap_or(false)
}
Prevention
- Always pass a value with -p/--package; never leave it dangling.
- In scripts, assert $1 is non-empty before forwarding to `cargo uninstall -p`.
When it happens
Trigger: Running `cargo uninstall --package` with no argument, or `cargo uninstall -p` followed by nothing.
Common situations: Shell quoting bug that swallowed the package name; copy-pasting a command missing the trailing spec; expecting `-p` to act as a flag rather than an option.
Related errors
- {}
- cannot specify both `@{v}` and `--version`
- missing crate name for `@{v}`
- argument for --color must be auto, always, or never, but fou
- subcommand is required, add a subcommand to the command alia
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/8e8d59a3c24b9bb9.json.
Report an issue: GitHub.