Skip to content

Feature Request: add suggestion for similarly named features with cargo add #15436

Open
@Jujumba

Description

@Jujumba

Problem

When adding a crate with certain features and misspelling one of them, cargo doesn't suggest features with similar names. This may be confusing if a crate has lots of features. For example:

$ cargo add axum_extra --features typed-headers  # The actual feature is `typed-header`, see the last row of disabled features
    Updating crates.io index
warning: translating `axum_extra` to `axum-extra`
      Adding axum-extra v0.10.1 to dependencies
error: unrecognized feature for crate axum-extra: typed-headers
disabled features:
    __private_docs, async-read-body, async-stream, attachment, cookie
    cookie-key-expansion, cookie-private, cookie-signed, erased-json
    error-response, file-stream, form, json-deserializer, json-lines, multipart
    protobuf, query, scheme, typed-header, typed-routing
enabled features:
    tracing

Proposed Solution

Instead of just listing all feature flags, cargo may additionally search for similarly named features and suggest them, so that it looks like the following:

$ cargo add axum_extra --features typed-headers
    Updating crates.io index
warning: translating `axum_extra` to `axum-extra`
      Adding axum-extra v0.10.1 to dependencies
error: unrecognized feature for crate axum-extra: typed-headers
help: a feature with a similar name exists: `typed-header`
disabled features:
    __private_docs, async-read-body, async-stream, attachment, cookie
    cookie-key-expansion, cookie-private, cookie-signed, erased-json
    error-response, file-stream, form, json-deserializer, json-lines, multipart
    protobuf, query, scheme, typed-header, typed-routing
enabled features:
    tracing

The help output here is worded the same way the compiler does

Notes

No response

Metadata

Metadata

Assignees

Labels

C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-addS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions