rust-lang/cargo · error · anyhow::Error
`cargo run` does not support glob patterns on target selecti
Error message
`cargo run` does not support glob patterns on target selection
What it means
`cargo run` can launch exactly one executable, so it refuses glob target selectors (e.g. `--bin 'foo*'`). The guard at cargo_run.rs:20 short-circuits before any target resolution when options.filter.contains_glob_patterns() is true.
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 0e07a15537)
Solutions
- Replace the glob with a concrete target name: `cargo run --bin app_cli`.
- If you need to run several binaries, invoke `cargo run` once per binary with an explicit --bin.
- Set `default-run` in Cargo.toml so you can omit --bin entirely.
Example fix
# before $ cargo run --bin 'app_*' error: `cargo run` does not support glob patterns on target selection # after $ cargo run --bin app_cli
Defensive patterns
Strategy: validation
Validate before calling
# Reject glob metacharacters in run target args: case "$*" in *[*?\[\]]*) echo "cargo run does not support glob patterns" >&2; exit 1;; esac cargo run "$@"
Prevention
- Always pass a concrete binary name to `cargo run`.
- Set `default-run` in Cargo.toml to avoid needing --bin.
- Don't reuse `cargo build` glob patterns for `cargo run`.
When it happens
Trigger: Passing a glob pattern to `cargo run`, such as `cargo run --bin 'app_*'` or `cargo run --example 't_*'`.
Common situations: Assuming `cargo run` supports the same glob syntax as `cargo build`/`cargo test`; shell expansions producing a pattern.
Related errors
- `cargo run` does not support glob pattern `{}` on package se
- running the file `{cmd}` requires `-Zscript`
- extra arguments to `{}` can only be passed to one target, co
- crate types to rustc can only be passed to one target, consi
- crate types can only be specified for libraries and example
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/1c43a962a9c76abd.json.
Report an issue: GitHub.