rust-lang/cargo · error

glob patterns on package selection are not supported.

Error message

glob patterns on package selection are not supported.

What it means

compile_options_for_single_package explicitly rejects glob metacharacters in --package values via restricted_names::is_glob_pattern. Cargo's -p selection requires concrete package names or pkgid SPECs; wildcards are not part of the selection model.

Solutions

  1. List each package explicitly: `cargo build -p foo -p bar`.
  2. Use workspace.default-members or `--workspace` to select groups.
  3. Drive selection through a script that enumerates packages via `cargo metadata`.

Example fix

# before
# cargo build -p 'my-*'

# after
# cargo build -p my-a -p my-b
# or: cargo build --workspace
Defensive patterns

Strategy: validation

Validate before calling

use cargo::util::restricted_names;

fn assert_no_glob(specs: &[String]) -> Result<(), String> {
    let bad: Vec<_> = specs.iter().filter(|s| restricted_names::is_glob_pattern(s)).collect();
    if bad.is_empty() { Ok(()) } else { Err(format!("glob chars not allowed in -p: {bad:?}")) }
}

Type guard

fn is_concrete_package_name(s: &str) -> bool {
    !cargo::util::restricted_names::is_glob_pattern(s)
}

Prevention

When it happens

Trigger: Calling `cargo <cmd> -p 'my-*'`, `-p '*crate'`, or any value containing `*`, `?`, `[`, or `]`.

Common situations: Expecting shell-glob or wildcard package selection in a monorepo; aliasing `-p` to a glob expansion that fails to match.

Related errors


AI-assisted analysis of rust-lang/cargo@98a09e7e7d (2026-08-11). Data as JSON: /api/errors/7b6b71446542939b. Report an issue: GitHub.

Appendix: source

Thrown at src/util/command_prelude.rs:893

    fn cli_features(&self) -> CargoResult<CliFeatures> {
        CliFeatures::from_command_line(
            &self._values_of("features"),
            self.flag("all-features"),
            !self.flag("no-default-features"),
        )
    }

    fn compile_options_for_single_package(
        &self,
        gctx: &GlobalContext,
        intent: UserIntent,
        workspace: Option<&Workspace<'_>>,
        profile_checking: ProfileChecking,
    ) -> CargoResult<CompileOptions> {
        let mut compile_opts = self.compile_options(gctx, intent, workspace, profile_checking)?;
        let spec = self._values_of("package");
        if spec.iter().any(restricted_names::is_glob_pattern) {
            anyhow::bail!("glob patterns on package selection are not supported.")
        }
        compile_opts.spec = Packages::Packages(spec);
        Ok(compile_opts)
    }

    fn new_options(&self, gctx: &GlobalContext) -> CargoResult<NewOptions> {
        let vcs = self._value_of("vcs").map(|vcs| {
            vcs.parse::<VersionControl>()
                .expect("clap ensures only valid values are present")
        });
        NewOptions::new(
            vcs,
            self.flag("bin"),
            self.flag("lib"),
            self.value_of_path("path", gctx).unwrap(),
            self._value_of("name").map(|s| s.to_string()),
            self._value_of("edition").map(|s| s.to_string()),
            self.registry(gctx)?,

View on GitHub (pinned to 98a09e7e7d)