]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/unnecessary_sort_by.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / unnecessary_sort_by.txt
1 ### What it does
2 Detects uses of `Vec::sort_by` passing in a closure
3 which compares the two arguments, either directly or indirectly.
4
5 ### Why is this bad?
6 It is more clear to use `Vec::sort_by_key` (or `Vec::sort` if
7 possible) than to use `Vec::sort_by` and a more complicated
8 closure.
9
10 ### Known problems
11 If the suggested `Vec::sort_by_key` uses Reverse and it isn't already
12 imported by a use statement, then it will need to be added manually.
13
14 ### Example
15 ```
16 vec.sort_by(|a, b| a.foo().cmp(&b.foo()));
17 ```
18 Use instead:
19 ```
20 vec.sort_by_key(|a| a.foo());
21 ```