Skip to content

Confusing error when entering wrong package name with features flag #16963

@ehuss

Description

@ehuss

Problem

If you mistype the package name to the -p flag and also specify the --features flag, then cargo emits a rather confusing error message:

error: cannot specify features for packages outside of workspace

If you're lucky, and the typo is close to an existing package name, then cargo may say something like:

help: a workspace member with a similar name exists: `foo-bar`

but even then the primary error message seems wrong, and the help text is incongruent with the error being about features.

Steps

  1. In some workspace, such as cargo's own workspace, run a command like cargo test -p foo_bar -F asdf

The actual features specified doesn't matter.

Possible Solution(s)

I would expect the error message to be the same as when --features is not specified:

error: package ID specification `foo_bar` did not match any packages

help: a workspace member with a similar name exists: `foo-bar`

Notes

No response

Version

cargo 1.97.0-nightly (4f9b52075 2026-05-01)
release: 1.97.0-nightly
commit-hash: 4f9b52075316e9ced380c8fa492858048d5758b6
commit-date: 2026-05-01
host: x86_64-unknown-linux-gnu
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.20.0-DEV (sys:0.4.88+curl-8.20.0 vendored ssl:OpenSSL/3.6.2)
ssl: OpenSSL 3.6.2 7 Apr 2026
os: Ubuntu 24.4.0 (noble) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions