{"id":"7b6b71446542939b","repo":"rust-lang/cargo","slug":"glob-patterns-on-package-selection-are-not-support","errorCode":null,"errorMessage":"glob patterns on package selection are not supported.","messagePattern":"glob patterns on package selection are not supported\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/util/command_prelude.rs","lineNumber":889,"sourceCode":"    fn cli_features(&self) -> CargoResult<CliFeatures> {\n        CliFeatures::from_command_line(\n            &self._values_of(\"features\"),\n            self.flag(\"all-features\"),\n            !self.flag(\"no-default-features\"),\n        )\n    }\n\n    fn compile_options_for_single_package(\n        &self,\n        gctx: &GlobalContext,\n        intent: UserIntent,\n        workspace: Option<&Workspace<'_>>,\n        profile_checking: ProfileChecking,\n    ) -> CargoResult<CompileOptions> {\n        let mut compile_opts = self.compile_options(gctx, intent, workspace, profile_checking)?;\n        let spec = self._values_of(\"package\");\n        if spec.iter().any(restricted_names::is_glob_pattern) {\n            anyhow::bail!(\"glob patterns on package selection are not supported.\")\n        }\n        compile_opts.spec = Packages::Packages(spec);\n        Ok(compile_opts)\n    }\n\n    fn new_options(&self, gctx: &GlobalContext) -> CargoResult<NewOptions> {\n        let vcs = self._value_of(\"vcs\").map(|vcs| match vcs {\n            \"git\" => VersionControl::Git,\n            \"hg\" => VersionControl::Hg,\n            \"pijul\" => VersionControl::Pijul,\n            \"fossil\" => VersionControl::Fossil,\n            \"none\" => VersionControl::NoVcs,\n            vcs => panic!(\"Impossible vcs: {:?}\", vcs),\n        });\n        NewOptions::new(\n            vcs,\n            self.flag(\"bin\"),\n            self.flag(\"lib\"),","sourceCodeStart":871,"sourceCodeEnd":907,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/command_prelude.rs#L871-L907","documentation":"compile_options_for_single_package reads the `-p`/`--package` values and checks each with restricted_names::is_glob_pattern. Cargo's package selection by SPEC does not support glob/wildcard characters (`*`, `?`, `[`), so any spec containing them is rejected.","triggerScenarios":"Passing a package specifier containing glob metacharacters to `-p`, e.g. `cargo build -p 'my-*'` or `cargo test -p 'crate?[abc]'`.","commonSituations":"Trying to select multiple crates by a common prefix using a shell glob; copying a glob from another tool (npm, make) into cargo; shell expansion that left a literal `*` because no files matched.","solutions":["List each package explicitly: `cargo build -p crate-a -p crate-b`.","Use `--workspace` to build all packages, or `-p` per crate for a prefix group.","Quote/escape to avoid the shell leaving literal glob chars, and remove any `*`/`?`/`[` from the SPEC."],"exampleFix":"# before\ncargo build -p 'my-*'\n\n# after\ncargo build -p my-a -p my-b\n# or all\ncargo build --workspace","handlingStrategy":"validation","validationCode":"fn clean_package_specs(specs: &[String]) -> Result<Vec<String>, anyhow::Error> {\n    for s in specs {\n        if restricted_names::is_glob_pattern(s) {\n            anyhow::bail!(\"package spec {s} contains glob characters; list packages explicitly\");\n        }\n    }\n    Ok(specs.to_vec())\n}","typeGuard":"fn is_valid_package_spec(s: &str) -> bool {\n    !restricted_names::is_glob_pattern(s) && !s.is_empty()\n}","tryCatchPattern":"match cli.compile_options_for_single_package(...) {\n    Err(e) if e.to_string().contains(\"glob patterns\") => {\n        eprintln!(\"list packages explicitly instead of using globs\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Never put `*`, `?`, or `[` in a `-p` value.","Quote shell arguments so unmatched globs don't leak literal `*`.","Use `--workspace` or explicit `-p` repeats for groups."],"tags":["cli","package-selection","glob","validation"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}