rust-lang/cargo · error
`cargo run` does not support glob patterns on target…
Error message
`cargo run` does not support glob patterns on target selection
What it means
Thrown by `cargo run` when the target selection filter contains glob patterns. Since `cargo run` can only execute a single binary, glob-based target matching (which could select multiple targets) is not supported and is rejected upfront.
Solutions
- Use `cargo run --bin <exact-name>` instead of a glob pattern.
- If building multiple targets, use `cargo build` instead of `cargo run`.
- Remove glob characters (`*`, `?`, `[`) from the target specification.
Example fix
# Before cargo run --bin 'my_*' # After — specify exact binary name cargo run --bin my_app
Defensive patterns
Strategy: validation
Validate before calling
fn contains_glob(s: &str) -> bool {
s.contains('*') || s.contains('?') || s.contains('[')
}
fn validate_no_glob_in_run(bin_name: &str) -> Result<(), String> {
if contains_glob(bin_name) {
return Err(format!("`cargo run` does not support glob patterns in --bin; `{}` contains glob chars", bin_name));
}
Ok(())
} Prevention
- Always specify exact binary names with `cargo run --bin <name>`.
- Do not pass glob patterns (`*`, `?`, `[`) to `cargo run`.
- Use `cargo build` if you need to select multiple targets via patterns.
When it happens
Trigger: Running `cargo run` with a target filter that includes glob patterns — e.g. passing something like `cargo run --bin 'my_*'` or using an API call with `CompileOptions` whose `filter` contains globs.
Common situations: Programmatically constructing `CompileOptions` with glob filters and calling `ops::run`; misunderstanding `cargo run`'s single-binary constraint versus `cargo build`'s multi-target support.
Related errors
- `cargo run` can run at most one executable, but multiple…
- a bin target must be available for `cargo run`
- `cargo run` could not determine which binary to run. Use…
- crate types to rustc can only be passed to one target…
- example target ` ` is a library and cannot be executed
AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11).
Data as JSON: /api/errors/1c43a962a9c76abd.
Report an issue: GitHub.
Appendix: source
Thrown at src/ops/cargo_run.rs:20
use std::fmt::Write as _;
use std::iter;
use std::path::Path;
use crate::compiler::UnitOutput;
use crate::ops;
use crate::util::CargoResult;
use crate::workspace::MaybePackage;
use crate::workspace::{TargetKind, Workspace};
pub fn run(
ws: &Workspace<'_>,
options: &ops::CompileOptions,
args: &[OsString],
) -> CargoResult<()> {
let gctx = ws.gctx();
if options.filter.contains_glob_patterns() {
anyhow::bail!("`cargo run` does not support glob patterns on target selection")
}
// We compute the `bins` here *just for diagnosis*. The actual set of
// packages to be run is determined by the `ops::compile` call below.
let packages = options.spec.get_packages(ws)?;
let bins: Vec<_> = packages
.into_iter()
.flat_map(|pkg| {
iter::repeat(pkg).zip(pkg.manifest().targets().iter().filter(|target| {
!target.is_lib()
&& !target.is_custom_build()
&& if !options.filter.is_specific() {
target.is_bin()
} else {
options.filter.target_run(target)
}
}))
})View on GitHub (pinned to eb98b54bc9)