{"id":"1c43a962a9c76abd","repo":"rust-lang/cargo","slug":"cargo-run-does-not-support-glob-patterns-on-targ","errorCode":null,"errorMessage":"`cargo run` does not support glob patterns on target selection","messagePattern":"`cargo run` does not support glob patterns on target selection","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_run.rs","lineNumber":20,"sourceCode":"use std::fmt::Write as _;\nuse std::iter;\nuse std::path::Path;\n\nuse crate::compiler::UnitOutput;\nuse crate::ops;\nuse crate::util::CargoResult;\nuse crate::workspace::MaybePackage;\nuse crate::workspace::{TargetKind, Workspace};\n\npub fn run(\n    ws: &Workspace<'_>,\n    options: &ops::CompileOptions,\n    args: &[OsString],\n) -> CargoResult<()> {\n    let gctx = ws.gctx();\n\n    if options.filter.contains_glob_patterns() {\n        anyhow::bail!(\"`cargo run` does not support glob patterns on target selection\")\n    }\n\n    // We compute the `bins` here *just for diagnosis*. The actual set of\n    // packages to be run is determined by the `ops::compile` call below.\n    let packages = options.spec.get_packages(ws)?;\n    let bins: Vec<_> = packages\n        .into_iter()\n        .flat_map(|pkg| {\n            iter::repeat(pkg).zip(pkg.manifest().targets().iter().filter(|target| {\n                !target.is_lib()\n                    && !target.is_custom_build()\n                    && if !options.filter.is_specific() {\n                        target.is_bin()\n                    } else {\n                        options.filter.target_run(target)\n                    }\n            }))\n        })","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_run.rs#L2-L38","documentation":"`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.","triggerScenarios":"Passing a glob pattern to `cargo run`, such as `cargo run --bin 'app_*'` or `cargo run --example 't_*'`.","commonSituations":"Assuming `cargo run` supports the same glob syntax as `cargo build`/`cargo test`; shell expansions producing a pattern.","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."],"exampleFix":"# before\n$ cargo run --bin 'app_*'\nerror: `cargo run` does not support glob patterns on target selection\n\n# after\n$ cargo run --bin app_cli","handlingStrategy":"validation","validationCode":"# Reject glob metacharacters in run target args:\ncase \"$*\" in\n  *[*?\\[\\]]*) echo \"cargo run does not support glob patterns\" >&2; exit 1;;\nesac\ncargo run \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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`."],"tags":["run","target-selection","glob"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}