Skip to content

Comments

fix(clippy): use sort_by_key instead of sort_by for reverse sorting#553

Merged
echobt merged 1 commit intomasterfrom
fix/clippy-sort-by-key-1770008415
Feb 2, 2026
Merged

fix(clippy): use sort_by_key instead of sort_by for reverse sorting#553
echobt merged 1 commit intomasterfrom
fix/clippy-sort-by-key-1770008415

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Feb 2, 2026

Summary

Fixes Clippy warnings that were treating sort_by with a simple comparator as errors.

Changes

cortex-apply-patch/src/backup.rs

  • Changed sort_by(|a, b| b.timestamp.cmp(&a.timestamp)) to sort_by_key(|b| std::cmp::Reverse(b.timestamp))

cortex-compact/src/auto_compaction/log_pruner.rs

  • Changed sort_by(|a, b| b.modified.cmp(&a.modified)) to sort_by_key(|f| std::cmp::Reverse(f.modified))

Why

Clippy's unnecessary_sort_by lint recommends using sort_by_key when the comparison is simply comparing a single field. This is more idiomatic and can be more efficient.

- Fix cortex-apply-patch backup.rs: use sort_by_key with Reverse
- Fix cortex-compact log_pruner.rs: use sort_by_key with Reverse

These changes address clippy::unnecessary_sort_by warnings.
@echobt echobt merged commit 5ec3fa9 into master Feb 2, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant