rust-lang/cargo · error · anyhow::Error

package pattern(s) ` ` not found in workspace

Error message

{}package pattern(s) `{}` not found in workspace `{}`

What it means

Thrown by emit_pattern_not_found for glob patterns passed to -p / --exclude that matched no workspace member. Distinct from error 72: this covers glob::Pattern inputs (e.g. `crates-*`) rather than exact names or full specs.

Solutions

  1. List member names and adjust the glob to actually match: `cargo metadata --no-deps | jq '.packages[].name'`.
  2. Replace the glob with explicit -p flags if only one or two members are intended.
  3. Verify the glob syntax (cargo uses glob::Pattern semantics: `*`, `?`, `[...]`).

Example fix

# before
cargo build -p 'deps-*'
# after (matches real prefix)
cargo build -p 'crates-*'
Defensive patterns

Strategy: validation

Validate before calling

// Pre-match globs against member names.
use glob::Pattern;
fn globs_match_any(members: &[String], pat: &str) -> bool {
    Pattern::new(pat).map(|p| members.iter().any(|m| p.matches(m))).unwrap_or(false)
}

Prevention

When it happens

Trigger: Running `cargo build -p 'deps-*'` when no member name starts with `deps-`; using a glob whose syntax matched nothing; --exclude with a wildcard that hits zero members.

Common situations: Wildcard patterns that no longer match after a reorganization; overly narrow patterns; copy-pasted globs from another workspace.

Related errors


AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11). Data as JSON: /api/errors/8f898393034d2a2f. Report an issue: GitHub.

Appendix: source

Thrown at src/ops/cargo_compile/packages.rs:206

            ws.root().display(),
        )
    }
    Ok(())
}

/// Emits "glob pattern not found" error.
fn emit_pattern_not_found(
    ws: &Workspace<'_>,
    opt_patterns: Vec<(glob::Pattern, bool)>,
    opt_out: bool,
) -> CargoResult<()> {
    let not_matched = opt_patterns
        .iter()
        .filter(|(_, matched)| !*matched)
        .map(|(pat, _)| pat.as_str())
        .collect::<Vec<_>>();
    if !not_matched.is_empty() {
        anyhow::bail!(
            "{}package pattern(s) `{}` not found in workspace `{}`",
            if opt_out { "excluded " } else { "" },
            not_matched.join(", "),
            ws.root().display(),
        )
    }
    Ok(())
}

fn emit_packages_not_found_within_workspace(
    ws: &Workspace<'_>,
    packages: &[String],
) -> CargoResult<()> {
    let (mut patterns, mut ids) = opt_patterns_and_ids(packages)?;
    let _: Vec<_> = ws
        .members()
        .filter(|pkg| {
            let id = ids.iter().find(|id| id.matches(pkg.package_id())).cloned();

View on GitHub (pinned to eb98b54bc9)