rust-lang/cargo · error
`cargo run` does not support glob pattern `{}` on package se
Error message
`cargo run` does not support glob pattern `{}` on package selection What it means
From run::exec (src/bin/cargo/commands/run.rs:57-66). `cargo run` must compile and execute exactly one binary, so it explicitly disallows glob patterns in -p/--package selection. It checks each package spec with util::restricted_names::is_glob_pattern and bails on the first match. Other commands (build/test) accept globs, but run does not because it cannot pick a single target from a glob.
Source
Thrown at src/bin/cargo/commands/run.rs:60
.arg_ignore_rust_version()
.arg_unit_graph()
.arg_timings()
.after_help(color_print::cstr!(
"Run `<bright-cyan,bold>cargo help run</>` for more detailed information.\n\
To pass `--help` to the specified binary, use `<bright-cyan,bold>-- --help</>`.\n",
))
}
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let ws = args.workspace(gctx)?;
let mut compile_opts =
args.compile_options(gctx, UserIntent::Build, Some(&ws), ProfileChecking::Custom)?;
// Disallow `spec` to be an glob pattern
if let Packages::Packages(opt_in) = &compile_opts.spec {
if let Some(pattern) = opt_in.iter().find(|s| is_glob_pattern(s)) {
return Err(anyhow::anyhow!(
"`cargo run` does not support glob pattern `{}` on package selection",
pattern,
)
.into());
}
}
if !args.contains_id("example") && !args.contains_id("bin") {
let default_runs: Vec<_> = compile_opts
.spec
.get_packages(&ws)?
.iter()
.filter_map(|pkg| pkg.manifest().default_run())
.collect();
if let [bin] = &default_runs[..] {
compile_opts.filter = CompileFilter::single_bin(bin.to_string());
} else {
// ops::run will take care of errors if len pkgs != 1.View on GitHub (pinned to 0e07a15537)
Solutions
- Name the exact package: `cargo run -p my-bin`.
- Use --bin/--example to pick the target explicitly.
- Run `cargo run` with no -p in a workspace whose default-run package is set in Cargo.toml.
Example fix
// before cargo run -p 'mycli_*' // after cargo run -p mycli-server # or: cargo run --bin mycli-server
Defensive patterns
Strategy: validation
Validate before calling
// Reject glob patterns in -p for `cargo run`
fn run_package_ok(spec: &str) -> bool {
!spec.contains(|c: char| matches!(c, '*' | '?' | '['))
}
if !pkgs.iter().all(|p| run_package_ok(p)) {
eprintln!("cargo run needs an exact package name, not a glob");
} Type guard
fn is_exact_package_name(s: &str) -> bool {
!s.contains(|c: char| matches!(c, '*' | '?' | '[' | ']'))
} Prevention
- Pass exact package (or --bin/--example) names to `cargo run`.
- Set [package] default-run in Cargo.toml so you can `cargo run` without -p.
- Don't reuse build/test glob selections for run.
When it happens
Trigger: `cargo run -p 'serde_*'` or `cargo run -p '*derive*'` — any -p value containing glob metacharacters (* ? [ ]).
Common situations: Reusing a `cargo build -p '<glob>'` invocation for run; shell glob expansion leaking a `*` into the argument; copying package-selection patterns from build/test scripts.
Related errors
- running the file `{cmd}` requires `-Zscript`
- {}package pattern(s) `{}` not found in workspace `{}`
- argument for --color must be auto, always, or never, but fou
- subcommand is required, add a subcommand to the command alia
- alias {} has unresolvable recursive definition: {} -> {}
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/8c35ff2912c74680.json.
Report an issue: GitHub.