summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/unnecessary_sort_by.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/src/docs/unnecessary_sort_by.txt')
-rw-r--r--src/tools/clippy/src/docs/unnecessary_sort_by.txt21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/unnecessary_sort_by.txt b/src/tools/clippy/src/docs/unnecessary_sort_by.txt
new file mode 100644
index 000000000..6913b62c4
--- /dev/null
+++ b/src/tools/clippy/src/docs/unnecessary_sort_by.txt
@@ -0,0 +1,21 @@
+### What it does
+Detects uses of `Vec::sort_by` passing in a closure
+which compares the two arguments, either directly or indirectly.
+
+### Why is this bad?
+It is more clear to use `Vec::sort_by_key` (or `Vec::sort` if
+possible) than to use `Vec::sort_by` and a more complicated
+closure.
+
+### Known problems
+If the suggested `Vec::sort_by_key` uses Reverse and it isn't already
+imported by a use statement, then it will need to be added manually.
+
+### Example
+```
+vec.sort_by(|a, b| a.foo().cmp(&b.foo()));
+```
+Use instead:
+```
+vec.sort_by_key(|a| a.foo());
+``` \ No newline at end of file