Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo add should maintain sorting of features #13578

Closed
Muscraft opened this issue Mar 13, 2024 · 3 comments · Fixed by #13682
Closed

cargo add should maintain sorting of features #13578

Muscraft opened this issue Mar 13, 2024 · 3 comments · Fixed by #13682
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-add S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@Muscraft
Copy link
Contributor

Muscraft commented Mar 13, 2024

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

@Muscraft Muscraft added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Mar 13, 2024
@epage epage changed the title Support sorting of features cargo add should maintain sorting of features Mar 13, 2024
@epage epage added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Mar 13, 2024
@epage
Copy link
Contributor

epage commented Mar 13, 2024

For implementing this, I'd ask that a new test get added in its own commit, showing the current behavior. A follow up commit within the PR would then add sorting-if-sorted of features, updating the test to show this new behavior.

We need to make sure we have test cases both for "unsorted, keep it that way" and "sorted, keep it that way".

@rohansx
Copy link

rohansx commented Mar 13, 2024

@Muscraft @epage I would like to take on this task

@rohansx
Copy link

rohansx commented Mar 17, 2024

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-add S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants