Skip to content

cargo add should maintain sorting of features #13578

Closed
@Muscraft

Description

@Muscraft

Problem

When you run cargo add <package> -F <feature> when the dependency already has features that are sorted alphabetically, the new features get added to the back instead of in alphabetical order. This is unexpected and different from what happens when you add a dependency to a sorted dependency list, where it respects being sorted (cargo code).

Example

Reproduction:

  1. Add below to [dependencies]
    snapbox = { version = "0.5.8", features = ["diff", "harness", "path", "term-svg"] }
  2. Run cargo add snapbox -F cmd
  3. See that cmd is not added to the front of the list

Proposed Solution

Cargo should keep features sorted alphabetically when encountered.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    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