{"record":{"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":"exception","errorClass":null,"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/cargo_run.rs#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"Programmatically constructing `CompileOptions` with glob filters and calling `ops::run`; misunderstanding `cargo run`'s single-binary constraint versus `cargo build`'s multi-target support.","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."],"exampleFix":"# Before\ncargo run --bin 'my_*'\n\n# After — specify exact binary name\ncargo run --bin my_app","handlingStrategy":"validation","validationCode":"fn contains_glob(s: &str) -> bool {\n    s.contains('*') || s.contains('?') || s.contains('[')\n}\nfn validate_no_glob_in_run(bin_name: &str) -> Result<(), String> {\n    if contains_glob(bin_name) {\n        return Err(format!(\"`cargo run` does not support glob patterns in --bin; `{}` contains glob chars\", bin_name));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cargo-run","glob","target-selection","binary"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}